Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

venv: activate.bat fails for venv with parentheses in PATH #80815

Closed
BWenzel mannequin opened this issue Apr 15, 2019 · 10 comments
Closed

venv: activate.bat fails for venv with parentheses in PATH #80815

BWenzel mannequin opened this issue Apr 15, 2019 · 10 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@BWenzel
Copy link
Mannequin

BWenzel mannequin commented Apr 15, 2019

BPO 36634
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @miss-islington
PRs
  • bpo-36634: Fixes activate.bat when existing values contain double quotes #15924
  • [3.8] bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924) #15968
  • [3.7] bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924) #15969
  • Files
  • activate.bat: avtivate.bat as created by venv
  • Report.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/zooba'
    closed_at = <Date 2019-09-11.15:00:33.935>
    created_at = <Date 2019-04-15.14:15:59.571>
    labels = ['type-bug', '3.8', '3.9', '3.7', 'library', 'OS-windows']
    title = 'venv: activate.bat fails for venv with parentheses in PATH'
    updated_at = <Date 2019-09-11.15:23:10.364>
    user = 'https://bugs.python.org/BWenzel'

    bugs.python.org fields:

    activity = <Date 2019-09-11.15:23:10.364>
    actor = 'miss-islington'
    assignee = 'steve.dower'
    closed = True
    closed_date = <Date 2019-09-11.15:00:33.935>
    closer = 'steve.dower'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2019-04-15.14:15:59.571>
    creator = 'BWenzel'
    dependencies = []
    files = ['48267', '48268']
    hgrepos = []
    issue_num = 36634
    keywords = ['patch']
    message_count = 10.0
    messages = ['340274', '340294', '340313', '340316', '340320', '340321', '340351', '351911', '351937', '351938']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'miss-islington', 'BWenzel']
    pr_nums = ['15924', '15968', '15969']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36634'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @BWenzel
    Copy link
    Mannequin Author

    BWenzel mannequin commented Apr 15, 2019

    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:
    pypa/virtualenv#35
    pypa/virtualenv#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.

    @BWenzel BWenzel mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 15, 2019
    @zooba
    Copy link
    Member

    zooba commented Apr 15, 2019

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

    @BWenzel
    Copy link
    Mannequin Author

    BWenzel mannequin commented Apr 16, 2019

    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

    @BWenzel
    Copy link
    Mannequin Author

    BWenzel mannequin commented Apr 16, 2019

    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.

    @BWenzel
    Copy link
    Mannequin Author

    BWenzel mannequin commented Apr 16, 2019

    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.

    @eryksun
    Copy link
    Contributor

    eryksun commented Apr 16, 2019

    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.

    @zooba
    Copy link
    Member

    zooba commented Apr 16, 2019

    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.

    @zooba zooba added 3.8 (EOL) end of life 3.9 only security fixes labels Sep 11, 2019
    @zooba zooba self-assigned this Sep 11, 2019
    @zware
    Copy link
    Member

    zware commented Sep 11, 2019

    New changeset 574b324 by Zachary Ware (Steve Dower) in branch 'master':
    bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
    574b324

    @zooba zooba closed this as completed Sep 11, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset 20f80bf by Miss Islington (bot) in branch '3.8':
    bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
    20f80bf

    @miss-islington
    Copy link
    Contributor

    New changeset 8a19a91 by Miss Islington (bot) in branch '3.7':
    bpo-36634: Fixes activate.bat when existing values contain double quotes (GH-15924)
    8a19a91

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants