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: activate for venv containing apostrophe doesn't work in powershell
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, eryksun, vinay.sajip, xtreak
Priority: normal Keywords: patch

Created on 2019-01-05 21:34 by cheryl.sabella, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14967 d3r3kk, 2019-07-26 19:03
Messages (4)
msg333075 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-01-05 21:34
On Windows 10, when I try to activate a venv in powershell where the name contains an apostrophe, I get the following error ("don't" is the name of the venv):

PS N:\projects\cpython\don't\Scripts> .\activate.ps1
At N:\projects\cpython\don't\Scripts\Activate.ps1:42 char:28
+     function global:prompt {
+                            ~
Missing closing '}' in statement block or type definition.
At N:\projects\cpython\don't\Scripts\Activate.ps1:37 char:40
+                                        ~
Missing closing '}' in statement block or type definition.
At N:\projects\cpython\don't\Scripts\Activate.ps1:43 char:61
+         Write-Host -NoNewline -ForegroundColor Green '(don't) '
+                                                             ~
Unexpected token ')' in expression or statement.
At N:\projects\cpython\don't\Scripts\Activate.ps1:43 char:63
+         Write-Host -NoNewline -ForegroundColor Green '(don't) '
+                                                               ~
The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEndCurlyBrace

This works OK in Command Prompt.
msg333116 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-01-06 18:17
From the error I think the quotes are not properly escaped while doing text replacement in venv activate file template at [0] while it's generated? On linux/Mac double quotes are used and hence the error is not triggered with single quote in virtualenv name. Using double quote in virtualenv name triggers the parse error.

$  python3.7 -m venv py37\"-bpo-35667-venv
$  source py37\"-bpo-35667-venv/bin/activate
py37"-bpo-35667-venv/bin/activate:57: parse error near `then'

Looking into the py37\"-bpo-35667-venv/bin/activate script there is below line where the double quote is unbalanced : 

    if [ "x(py37"-bpo-35667-venv) " != x ] ; then
	PS1="(py37"-bpo-35667-venv) ${PS1:-}"

I tried escaping the quotes with backslash at [0] but I get a similar error. I guess it's similar case in Powershell as I can see from Activate.ps1 but I haven't tested it. I am not sure about the difference in semantics between powershell and command prompt with respect to quoting since I don't have access to Windows.

py37\'-bpo-35667-venv/bin/Activate.ps1 file with unbalanced quote

    function global:prompt {
        Write-Host -NoNewline -ForegroundColor Green '(py37'-bpo-35667-venv) '

msg333125 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-01-07 00:09
> I am not sure about the difference in semantics between powershell and 
> command prompt with respect to quoting since

CMD only uses single quotes in `for /f` loops, in which it's either a command or a literal string (w/ the "usebackq" option). This is not a problem in activate.bat. 

Double quotes in file names generally shouldn't be a problem in Windows. As far as I know, only the named-pipe file system allows them in pipe-file names (e.g. r'\\?\pipe\"pipename"'), and for regular files they're allowed in stream names (e.g. 'filename:"streamname"'). Otherwise, double quote should be reserved in file names as the DOS_DOT wildcard character.
msg351405 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-09-09 10:22
This has reportedly been fixed by the changes made to fix bpo-37354. I'll close this, but please reopen if you find it's still a problem.
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 79848
2019-09-09 10:22:37vinay.sajipsetstatus: open -> closed
resolution: fixed
messages: + msg351405

stage: patch review -> resolved
2019-07-26 19:03:13d3r3kksetkeywords: + patch
stage: patch review
pull_requests: + pull_request14736
2019-01-07 00:09:14eryksunsetnosy: + eryksun
messages: + msg333125
2019-01-06 18:17:40xtreaksetnosy: + vinay.sajip, xtreak
messages: + msg333116
2019-01-05 21:34:29cheryl.sabellacreate