This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: venv: activate.bat fails for venv with parentheses in PATH
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: BWenzel, eryksun, miss-islington, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2019-04-15 14:15 by BWenzel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
activate.bat BWenzel, 2019-04-16 06:57 avtivate.bat as created by venv
Report.patch BWenzel, 2019-04-16 07:14
Pull Requests
URL Status Linked Edit
PR 15924 merged steve.dower, 2019-09-11 11:35
PR 15968 merged miss-islington, 2019-09-11 14:41
PR 15969 merged miss-islington, 2019-09-11 14:41
Messages (10)
msg340274 - (view) Author: Bastian Wenzel (BWenzel) Date: 2019-04-15 14:15
After creating a virtual environment on win 7 (64bit) with:
py -3.7 -m venv venv

Running venv\Scripts\activate.bat will yield this result:
\Common was unexpected at this time.
(venv) C:\...

My PATH variable contains a path that starts with:
C:\Program Files (x86)\Common Files\...

To me this looks like this issue for virtualenv:
https://github.com/pypa/virtualenv/issues/35
https://github.com/pypa/virtualenv/pull/839

Running:
(venv) C:\Tools\venv_test>where python
C:\Python34\python.exe

This is my default python on PATH. Doing this with virtualenv:
(virtualenv) C:\Tools\venv_test>where python
C:\Tools\venv_test\virtualenv\Scripts\python.exe
C:\Python34\python.exe

I really hope this is not a duplicate.
msg340294 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-04-15 16:27
Basically everyone has that directory in their PATH - we'd be hearing a lot more issues if it were a consistent bug.

Can you share the full contents of your activate.bat file? And if it's okay, your full PATH variable (before and after running activate.bat)

(You may not want to share PATH if there are applications in there that you don't want to be seen publicly - in that case, can you randomize letters rather than deleting them? e.g. "System32"->"Xborpm99" That way we won't lose potentially important information to this bug like punctuation.)
msg340313 - (view) Author: Bastian Wenzel (BWenzel) Date: 2019-04-16 06:57
I have attached the activate.bat script that got generated by venv.

My current path looks like this (added line breaks for readability):

C:\Program Files\Git\bin;
C:\Tools\antlr;
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\ProgramData\Oracle\Java\javapath;
C:\windows\system32;
C:\windows;
C:\windows\System32\Wbem;
C:\windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\CheckPoint\Endpoint Security\Endpoint Common\bin;
C:\Program Files\IBM\Informix\Client-SDK;
C:\Program Files\IBM\Informix\Client-SDK\bin\netf20;
C:\Python34\;
C:\Python34\Scripts;
C:\Dwimperl\perl\bin;
C:\Dwimperl\perl\site\bin;
C:\Dwimperl\c\bin;
C:\Program Files\TortoiseSVN\bin;
C:\Program Files\Git LFS;
C:\Users\a0000000\Downloads\chromedriver_win32;
C:\Program Files (x86)\PuTTY\;
C:\Program Files\doxygen\bin;
C:\Strawberry\c\bin;
C:\Strawberry\perl\site\bin;
C:\Strawberry\perl\bin;
C:\Projects\tex\MiKTeX 2.9\miktex\bin\x64\;
C:\Program Files\MATLAB\R2017b\runtime\win64;
C:\Program Files\MATLAB\R2017b\bin;
C:\Program Files (x86)\Koenmdpk\AG-WC\Version Selector Plus\;
%AGWCROOT%\bin;
%SSLROOT%;
%IBISUROOT%;
C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;
C:\Program Files\dotnet\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\HashiCorp\Vagrant\bin;
%systemroot%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Git\usr\bin;
%systemroot%\System32\WindowsPowerShell\v1.0\;
%systemroot%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\TortoiseGit\bin

%IBISUROOT%=C:\Program Files (x86)\Koenmdpk\ibisu\
%SSLROOT%=C:\Program Files (x86)\Koenmdpk\SSL\
%AGWCROOT%=C:\Program Files (x86)\Koenmdpk\AG-WC\3.60.30
%systemroot%=C:\windows
msg340316 - (view) Author: Bastian Wenzel (BWenzel) Date: 2019-04-16 07:14
So if I replace this section from venv's activate.bat:
if defined _OLD_VIRTUAL_PATH (
    set "PATH=%_OLD_VIRTUAL_PATH%"
) else (
    set "_OLD_VIRTUAL_PATH=%PATH%"
)

with the part from virtualenv's activate.bat:

REM if defined _OLD_VIRTUAL_PATH (
if not defined _OLD_VIRTUAL_PATH goto ENDIFVPATH1
    set "PATH=%_OLD_VIRTUAL_PATH%"
:ENDIFVPATH1
REM ) else (
if defined _OLD_VIRTUAL_PATH goto ENDIFVPATH2
    set "_OLD_VIRTUAL_PATH=%PATH%"
:ENDIFVPATH2

then venv\Scrtips\activate.bat seems to behave as expected.
msg340320 - (view) Author: Bastian Wenzel (BWenzel) Date: 2019-04-16 08:15
Ok I think I found my problem. The system path of of my machine is ok but my user path contains a stray double quotation mark (") like this:

C:\Program Files\Git\bin";C:\Tools\antlr;C:\Program Files (x86)\Common Files\Oracle\Java\javapath ...

With this I am closing the double quotation of the .bat file too early and this leads to an early closing ).

If I remove it venv\Script\activate.bat behaves as expected. 

Sorry for taking up your time.
msg340321 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-04-16 08:49
> my user path contains a stray double quotation mark (")

Steve, do you think we should work around this by first removing double quote characters from PATH? This will fix the user's PATH, making one or more directories searchable again, but it could have side effects.
msg340351 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-04-16 16:01
We should be able to use alternate characters in the SET call, or just drop the quotes completely. In theory they make sense, but there's no trailing whitespace to worry about here.
msg351911 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-09-11 14:41
New changeset 574b324bdc9a126b5a4488c3613f11ad2555415e by Zachary Ware (Steve Dower) in branch 'master':
bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
https://github.com/python/cpython/commit/574b324bdc9a126b5a4488c3613f11ad2555415e
msg351937 - (view) Author: miss-islington (miss-islington) Date: 2019-09-11 15:22
New changeset 20f80bfc83506037e40d918fcac887cee9093c93 by Miss Islington (bot) in branch '3.8':
bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
https://github.com/python/cpython/commit/20f80bfc83506037e40d918fcac887cee9093c93
msg351938 - (view) Author: miss-islington (miss-islington) Date: 2019-09-11 15:23
New changeset 8a19a91e28b86592ee1ad9d1761e59b30d8511b9 by Miss Islington (bot) in branch '3.7':
bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
https://github.com/python/cpython/commit/8a19a91e28b86592ee1ad9d1761e59b30d8511b9
History
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 80815
2019-09-11 15:23:10miss-islingtonsetmessages: + msg351938
2019-09-11 15:22:01miss-islingtonsetnosy: + miss-islington
messages: + msg351937
2019-09-11 15:00:33steve.dowersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-11 14:41:38miss-islingtonsetpull_requests: + pull_request15602
2019-09-11 14:41:32miss-islingtonsetpull_requests: + pull_request15601
2019-09-11 14:41:24zach.waresetmessages: + msg351911
2019-09-11 11:35:26steve.dowersetstage: patch review
pull_requests: + pull_request15564
2019-09-11 11:33:55steve.dowersetassignee: steve.dower
versions: + Python 3.8, Python 3.9
2019-04-16 16:01:04steve.dowersetmessages: + msg340351
2019-04-16 08:49:07eryksunsetnosy: + eryksun
messages: + msg340321
2019-04-16 08:15:58BWenzelsetmessages: + msg340320
2019-04-16 07:14:27BWenzelsetfiles: + Report.patch
keywords: + patch
messages: + msg340316
2019-04-16 06:57:04BWenzelsetfiles: + activate.bat

messages: + msg340313
2019-04-15 16:27:47steve.dowersetmessages: + msg340294
2019-04-15 14:25:46xtreaksetnosy: + tim.golden, steve.dower, zach.ware, paul.moore
components: + Windows
2019-04-15 14:15:59BWenzelcreate