pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.82k stars 1.03k forks source link

Virtualenv Name Incorrect When Activated with Powershell Script #2090

Open Anti-Distinctlyminty opened 3 years ago

Anti-Distinctlyminty commented 3 years ago

Issue

When using the Activate.ps1 script, the name in parenthesis becomes (activate.ps1), as opposed to the name of the virtual environment when using the bat file.

Environment

Provide at least:

Output ```console Package Version ------------------ -------------- -ip 20.1.1 -irtualenv 20.4.3 <-- This looks suspicious appdirs 1.4.4 atomicwrites 1.3.0 attrs 19.3.0 autopep8 1.5 cairocffi 1.2.0 CairoSVG 2.5.2 certifi 2020.12.5 cffi 1.14.5 chardet 4.0.0 colorama 0.4.1 cssselect2 0.4.1 defusedxml 0.7.1 distlib 0.3.1 expandvars 0.6.5 filelock 3.0.12 future-fstrings 1.2.0 html5lib 1.1 idna 2.10 importlib-metadata 3.10.0 jsonschema 2.6.0 logging-tree 1.8 logx 0.1.1562053912 mistune 0.8.4 more-itertools 8.0.0 mutagen 1.45.1 packaging 19.2 peewee 3.13.3 pgpubsub 0.0.5 Pillow 8.1.2 pip 21.0.1 pluggy 0.13.1 psycopg2-binary 2.8.4 ptvsd 4.3.2 py 1.8.0 pycodestyle 2.5.0 pycparser 2.20 pyparsing 2.4.5 Pyphen 0.10.0 pyseq 0.5.1 pytest 5.3.1 PyYAML 5.2 requests 2.25.1 sentry-sdk 0.19.4 setuptools 47.1.0 setuptools-scm 3.5.0 simplejson 3.17.0 six 1.15.0 spotipy 2.16.1 tinycss2 1.1.0 typing-extensions 3.7.4.3 urllib3 1.26.4 virtualenv 20.4.3 wcwidth 0.1.7 WeasyPrint 52.4 webencodings 0.5.1 youtube-dl 2021.3.25 zipp 3.4.1 ```

Output of the virtual environment creation

Make sure to run the creation with -vvv --with-traceback:

The REDACTED_PATH listed below in Output is a UNC path. Maybe this is the cause?

Output ```console 183 setup logging to NOTSET [DEBUG report:43] 280 find interpreter for spec PythonSpec(path=c:\python37\python.exe) [INFO builtin:62] 280 proposed PythonInfo(spec=CPython3.7.3.final.0-64, exe=c:\python37\python.exe, platform=win32, version='3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [INFO builtin:69] 280 accepted PythonInfo(spec=CPython3.7.3.final.0-64, exe=c:\python37\python.exe, platform=win32, version='3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [DEBUG builtin:71] 292 symlink on filesystem does not work [DEBUG info:47] 293 filesystem is not case-sensitive [DEBUG info:28] 474 create virtual environment via CPython3Windows(dest=\\REDACTED_PATH\.test, clear=False, no_vcs_ignore=False, global=False) [INFO session:52] 490 create folder \\REDACTED_PATH\.test\Lib\site-packages [DEBUG _sync:25] 576 create folder \\REDACTED_PATH\.test\Scripts [DEBUG _sync:25] 617 write \\REDACTED_PATH\.test\pyvenv.cfg [DEBUG pyenv_cfg:34] 618 home = c:\python37 [DEBUG pyenv_cfg:38] 618 implementation = CPython [DEBUG pyenv_cfg:38] 619 version_info = 3.7.3.final.0 [DEBUG pyenv_cfg:38] 619 virtualenv = 20.4.3 [DEBUG pyenv_cfg:38] 620 include-system-site-packages = false [DEBUG pyenv_cfg:38] 620 base-prefix = c:\python37 [DEBUG pyenv_cfg:38] 620 base-exec-prefix = c:\python37 [DEBUG pyenv_cfg:38] 621 base-executable = c:\python37\python.exe [DEBUG pyenv_cfg:38] 681 copy c:\python37\Lib\venv\scripts\nt\python.exe to \\REDACTED_PATH\.test\Scripts\python.exe [DEBUG _sync:52] 1098 copy c:\python37\Lib\venv\scripts\nt\pythonw.exe to \\REDACTED_PATH\.test\Scripts\pythonw.exe [DEBUG _sync:52] 1513 create virtualenv import hook file \\REDACTED_PATH\.test\Lib\site-packages\_virtualenv.pth [DEBUG api:95] 1554 create \\REDACTED_PATH\.test\Lib\site-packages\_virtualenv.py [DEBUG api:98] 1644 ============================== target debug ============================== [DEBUG session:54] 1645 debug via '\\REDACTED_PATH\.test\Scripts\python.exe' 'c:\python37\lib\site-packages\virtualenv\create\debug.py' [DEBUG creator:224] 1644 { "sys": { "executable": "\\\\192.168.15.130\\projects\\__Tests\\Python\\expandvars\\.test\\Scripts\\python.exe", "_base_executable": "c:\\python37\\python.exe", "prefix": "\\\\192.168.15.130\\projects\\__Tests\\Python\\expandvars\\.test", "base_prefix": "c:\\python37", "real_prefix": null, "exec_prefix": "\\\\192.168.15.130\\projects\\__Tests\\Python\\expandvars\\.test", "base_exec_prefix": "c:\\python37", "path": [ "c:\\python37\\python37.zip", "c:\\python37\\DLLs", "c:\\python37\\lib", "c:\\python37", "\\\\192.168.15.130\\projects\\__Tests\\Python\\expandvars\\.test", "\\\\192.168.15.130\\projects\\__Tests\\Python\\expandvars\\.test\\lib\\site-packages" ], "meta_path": [ "", "", "", "" ], "fs_encoding": "utf-8", "io_encoding": "cp1252" }, "version": "3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]", "makefile_filename": "c:\\python37\\Lib\\config\\Makefile", "os": "", "site": "", "datetime": "", "math": "", "json": "" } [DEBUG session:55] 3622 add seed packages via FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Luke\AppData\Local\pypa\virtualenv) [INFO session:59] 3626 got embed update of distribution pip from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\pip.json [DEBUG via_disk_folder:135] 3626 got embed update of distribution setuptools from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\setuptools.json [DEBUG via_disk_folder:135] 3627 got embed update of distribution wheel from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\wheel.json [DEBUG via_disk_folder:135] 3632 got embed update of distribution pip from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\pip.json [DEBUG via_disk_folder:135] 3632 got embed update of distribution setuptools from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\setuptools.json [DEBUG via_disk_folder:135] 3632 got embed update of distribution wheel from C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\embed\1\wheel.json [DEBUG via_disk_folder:135] 3634 install pip from wheel c:\python37\lib\site-packages\virtualenv\seed\wheels\embed\pip-21.0.1-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:49] 3634 install setuptools from wheel c:\python37\lib\site-packages\virtualenv\seed\wheels\embed\setuptools-54.1.2-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:49] 3636 Attempting to acquire lock 2346170248384 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any.lock [DEBUG filelock:270] 3636 install wheel from wheel c:\python37\lib\site-packages\virtualenv\seed\wheels\embed\wheel-0.36.2-py2.py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:49] 3636 Attempting to acquire lock 2346170249000 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any.lock [DEBUG filelock:270] 3637 Lock 2346170248384 acquired on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any.lock [INFO filelock:274] 3637 Attempting to acquire lock 2346170112992 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any.lock [DEBUG filelock:270] 3638 Lock 2346170249000 acquired on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any.lock [INFO filelock:274] 3639 Attempting to release lock 2346170248384 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any.lock [DEBUG filelock:315] 3640 Lock 2346170112992 acquired on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any.lock [INFO filelock:274] 3640 Attempting to release lock 2346170249000 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any.lock [DEBUG filelock:315] 3640 Attempting to release lock 2346170112992 on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any.lock [DEBUG filelock:315] 3640 Lock 2346170248384 released on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any.lock [INFO filelock:318] 3641 Lock 2346170249000 released on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any.lock [INFO filelock:318] 3642 Lock 2346170112992 released on C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any.lock [INFO filelock:318] 3643 copy C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\distutils-precedence.pth to \\REDACTED_PATH\.test\Lib\site-packages\distutils-precedence.pth [DEBUG _sync:52] 3646 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any\pip to \\REDACTED_PATH\.test\Lib\site-packages\pip [DEBUG _sync:52] 3649 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any\wheel to \\REDACTED_PATH\.test\Lib\site-packages\wheel [DEBUG _sync:52] 3776 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\pkg_resources to \\REDACTED_PATH\.test\Lib\site-packages\pkg_resources [DEBUG _sync:52] 5118 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any\wheel-0.36.2.dist-info to \\REDACTED_PATH\.test\Lib\site-packages\wheel-0.36.2.dist-info [DEBUG _sync:52] 5646 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\setuptools to \\REDACTED_PATH\.test\Lib\site-packages\setuptools [DEBUG _sync:52] 5736 copy C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\wheel-0.36.2-py2.py3-none-any\wheel-0.36.2.virtualenv to \\REDACTED_PATH\.test\Lib\site-packages\wheel-0.36.2.virtualenv [DEBUG _sync:52] 6059 generated console scripts wheel.exe wheel3.exe wheel-3.7.exe wheel3.7.exe [DEBUG base:48] 16516 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\setuptools-54.1.2.dist-info to \\REDACTED_PATH\.test\Lib\site-packages\setuptools-54.1.2.dist-info [DEBUG _sync:52] 17198 copy C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\setuptools-54.1.2.virtualenv to \\REDACTED_PATH\.test\Lib\site-packages\setuptools-54.1.2.virtualenv [DEBUG _sync:52] 17240 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\setuptools-54.1.2-py3-none-any\_distutils_hack to \\REDACTED_PATH\.test\Lib\site-packages\_distutils_hack [DEBUG _sync:52] 17453 generated console scripts [DEBUG base:48] 37593 copy directory C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any\pip-21.0.1.dist-info to \\REDACTED_PATH\.test\Lib\site-packages\pip-21.0.1.dist-info [DEBUG _sync:52] 38245 copy C:\Users\Luke\AppData\Local\pypa\virtualenv\wheel\3.7\image\1\CopyPipInstall\pip-21.0.1-py3-none-any\pip-21.0.1.virtualenv to \\REDACTED_PATH\.test\Lib\site-packages\pip-21.0.1.virtualenv [DEBUG _sync:52] 38580 generated console scripts pip3.exe pip.exe pip3.7.exe pip-3.7.exe [DEBUG base:48] 38581 add activators for Bash, Batch, Fish, PowerShell, Python, Xonsh [INFO session:66] 38905 write \\REDACTED_PATH\.test\pyvenv.cfg [DEBUG pyenv_cfg:34] 38906 home = c:\python37 [DEBUG pyenv_cfg:38] 38906 implementation = CPython [DEBUG pyenv_cfg:38] 38906 version_info = 3.7.3.final.0 [DEBUG pyenv_cfg:38] 38906 virtualenv = 20.4.3 [DEBUG pyenv_cfg:38] 38907 include-system-site-packages = false [DEBUG pyenv_cfg:38] 38907 base-prefix = c:\python37 [DEBUG pyenv_cfg:38] 38907 base-exec-prefix = c:\python37 [DEBUG pyenv_cfg:38] 38907 base-executable = c:\python37\python.exe [DEBUG pyenv_cfg:38] 38969 created virtual environment CPython3.7.3.final.0-64 in 38789ms creator CPython3Windows(dest=\\REDACTED_PATH\.test, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Luke\AppData\Local\pypa\virtualenv) added seed packages: pip==21.0.1, setuptools==54.1.2, wheel==0.36.2 activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator [WARNING __main__:19] ```
gaborbernat commented 3 years ago

A PR fixing this would be appreciated.

shireenrao commented 3 years ago

Hello - Is this error specific to OP's environment and his packages installed in the environment? I tried creating a new virtualenv and didn't see the issue. Both cmd's activate and powershell's activate show the correct virtualenv name.

Anti-Distinctlyminty commented 3 years ago

Odd. I am no longer seeing it. I shall reopen if I can reproduce.

Anti-Distinctlyminty commented 2 years ago

I've ended up back here again. Again it does seem to be something to do with UNC paths. I've created a virual environment on a network drive. To reproduce:

In powershell navigate to some network location using a mapped drive and create the virtual env:

PS > cd T:\__Tests\temp
PS T:\__Tests\temp > C:\Python27\python.exe -m virtualenv .venv -vvv

Activate it. As shown here you may have to set the execution policy

PS T:\__Tests\temp > set-executionpolicy unrestricted -scope process
PS T:\__Tests\temp > .venv\Scritps\activate

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this
script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run
T:\__Tests\temp\.venv\Scripts\activate.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r

(.venv) PS T:\__Tests\temp > py
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Ok, all good. Now let's use exactly the same .venv on a UNC path...

PS Microsoft.PowerShell.Core\FileSystem::\\x.x.x.x\__Tests\temp> .\.venv\Scripts\activate

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this
script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run
\\192.168.15.130\projects\__Tests\temp\.venv\Scripts\activate.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
(activate.ps1) PS Microsoft.PowerShell.Core\FileSystem::\\x.x.x.x\__Tests\temp> py
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Not only is the virtualenv name incorrect, but the activation isn't actually working, it just picks up whatever python is first on path. Checking the path environment shows why, as the injected path is clearly incorrect.

(activate.ps1) PS Microsoft.PowerShell.Core\FileSystem::\\x.x.x.x\__Tests\temp> echo $env:PATH
Microsoft.PowerShell.Core\FileSystem::\\x.x.x.x\__Tests\temp\.venv\Scripts\activate.ps1/Scripts;...

virtualenv version 20.14.0