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

Created on 2019-04-15 14:15 by BWenzel, last changed 2019-04-16 16:01 by steve.dower.

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
Messages (7)
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.
History
Date User Action Args
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