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.

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
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.

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:

(venv) C:\Tools\venv_test>where python

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

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:\Program Files (x86)\Common Files\Oracle\Java\javapath;
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:\Program Files\TortoiseSVN\bin;
C:\Program Files\Git LFS;
C:\Program Files (x86)\PuTTY\;
C:\Program Files\doxygen\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\;
C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;
C:\Program Files\dotnet\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Program Files\Git\usr\bin;
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
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 (
) else (

with the part from virtualenv's activate.bat:

REM if defined _OLD_VIRTUAL_PATH (
if not defined _OLD_VIRTUAL_PATH goto ENDIFVPATH1
REM ) else (

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)
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)
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)
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