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

Windows PATH environment variable is not set correctly #2414

Open
OmerFI opened this issue Sep 10, 2022 · 6 comments
Open

Windows PATH environment variable is not set correctly #2414

OmerFI opened this issue Sep 10, 2022 · 6 comments

Comments

@OmerFI
Copy link

OmerFI commented Sep 10, 2022

Issue

Windows PATH environment variable is not set correctly

Description

I have created a virtualenv using this command on Windows: virtualenv venv
and I activated it: venv\Scripts\activate.bat

The full path of the virtualenv is this: C:\Users\omerg\Desktop\Ömer\venv

But when I try to use pip, the system uses global pip installed on C:\Python310\lib\site-packages\pip instead of C:\Users\omerg\Desktop\Ömer\venv\Scripts\pip

resim

I am investigating, what I found is that the PATH environment variable is not set correctly.

My venv\Scripts\activate.bat is something like this:

@set "VIRTUAL_ENV=C:\Users\omerg\Desktop\Ömer\venv"
...
@set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"

But when I try to echo the VIRTUAL_ENV or PATH environment variable
I am seeing this

resim

But when I try to set VIRTUAL_ENV env var manually, there is no problem

resim

Environment

  • OS: Windows 11
  • virtualenv 20.16.5

Output of the virtual environment creation

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

177 setup logging to NOTSET [DEBUG report:35]
203 find interpreter for spec PythonSpec(path=C:\Python310\python.exe) [INFO builtin:56]
203 proposed PythonInfo(spec=CPython3.10.0.final.0-64, exe=C:\Python310\python.exe, platform=win32, version='3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [INFO builtin:63]
203 accepted PythonInfo(spec=CPython3.10.0.final.0-64, exe=C:\Python310\python.exe, platform=win32, version='3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [DEBUG builtin:65]
208 symlink on filesystem does not work [DEBUG info:43]
209 filesystem is not case-sensitive [DEBUG info:24]
291 create virtual environment via CPython3Windows(dest=C:\Users\omerg\Desktop\Ömer\venv, clear=False, no_vcs_ignore=False, global=False) [INFO session:48]
291 create folder C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages [DEBUG _sync:9]
292 create folder C:\Users\omerg\Desktop\Ömer\venv\Scripts [DEBUG _sync:9]
293 write C:\Users\omerg\Desktop\Ömer\venv\pyvenv.cfg [DEBUG pyenv_cfg:30]
293     home = C:\Python310 [DEBUG pyenv_cfg:34]
293     implementation = CPython [DEBUG pyenv_cfg:34]
293     version_info = 3.10.0.final.0 [DEBUG pyenv_cfg:34]
293     virtualenv = 20.16.5 [DEBUG pyenv_cfg:34]
294     include-system-site-packages = false [DEBUG pyenv_cfg:34]
294     base-prefix = C:\Python310 [DEBUG pyenv_cfg:34]
294     base-exec-prefix = C:\Python310 [DEBUG pyenv_cfg:34]
294     base-executable = C:\Python310\python.exe [DEBUG pyenv_cfg:34]
295 copy C:\Python310\Lib\venv\scripts\nt\python.exe to C:\Users\omerg\Desktop\Ömer\venv\Scripts\python.exe [DEBUG _sync:36]
297 copy C:\Python310\Lib\venv\scripts\nt\pythonw.exe to C:\Users\omerg\Desktop\Ömer\venv\Scripts\pythonw.exe [DEBUG _sync:36]
299 create virtualenv import hook file C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\_virtualenv.pth [DEBUG api:89]
300 create C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\_virtualenv.py [DEBUG api:92]
302 ============================== target debug ============================== [DEBUG session:50]
303 debug via 'C:\Users\omerg\Desktop\Ömer\venv\Scripts\python.exe' 'C:\Python310\lib\site-packages\virtualenv\create\debug.py' [DEBUG creator:197]
303 {
  "sys": {
    "executable": "C:\\Users\\omerg\\Desktop\\\u00d6mer\\venv\\Scripts\\python.exe",
    "_base_executable": "C:\\Python310\\python.exe",
    "prefix": "C:\\Users\\omerg\\Desktop\\\u00d6mer\\venv",
    "base_prefix": "C:\\Python310",
    "real_prefix": null,
    "exec_prefix": "C:\\Users\\omerg\\Desktop\\\u00d6mer\\venv",
    "base_exec_prefix": "C:\\Python310",
    "path": [
      "C:\\Python310\\python310.zip",
      "C:\\Python310\\DLLs",
      "C:\\Python310\\lib",
      "C:\\Python310",
      "C:\\Users\\omerg\\Desktop\\\u00d6mer\\venv",
      "C:\\Users\\omerg\\Desktop\\\u00d6mer\\venv\\lib\\site-packages"
    ],
    "meta_path": [
      "<class '_virtualenv._Finder'>",
      "<class '_frozen_importlib.BuiltinImporter'>",
      "<class '_frozen_importlib.FrozenImporter'>",
      "<class '_frozen_importlib_external.PathFinder'>"
    ],
    "fs_encoding": "utf-8",
    "io_encoding": "cp1254"
  },
  "version": "3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]",
  "makefile_filename": "C:\\Python310\\Lib\\config\\Makefile",
  "os": "<module 'os' from 'C:\\\\Python310\\\\lib\\\\os.py'>",
  "site": "<module 'site' from 'C:\\\\Python310\\\\lib\\\\site.py'>",
  "datetime": "<module 'datetime' from 'C:\\\\Python310\\\\lib\\\\datetime.py'>",
  "math": "<module 'math' (built-in)>",
  "json": "<module 'json' from 'C:\\\\Python310\\\\lib\\\\json\\\\__init__.py'>"
} [DEBUG session:51]
459 add seed packages via FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\omerg\AppData\Local\pypa\virtualenv) [INFO session:55]
466 got embed update of distribution pip from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\pip.json [DEBUG via_disk_folder:129]
467 got embed update of distribution setuptools from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\setuptools.json [DEBUG via_disk_folder:129]
467 got embed update of distribution wheel from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\wheel.json [DEBUG via_disk_folder:129]
476 got embed update of distribution pip from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\pip.json [DEBUG via_disk_folder:129]
476 got embed update of distribution setuptools from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\setuptools.json [DEBUG via_disk_folder:129]
477 got embed update of distribution wheel from C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\embed\3\wheel.json [DEBUG via_disk_folder:129]
479 install pip from wheel C:\Python310\lib\site-packages\virtualenv\seed\wheels\embed\pip-22.2.2-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:47]
480 install setuptools from wheel C:\Python310\lib\site-packages\virtualenv\seed\wheels\embed\setuptools-65.3.0-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:47]
480 install wheel from wheel C:\Python310\lib\site-packages\virtualenv\seed\wheels\embed\wheel-0.37.1-py2.py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:47]
481 Attempting to acquire lock 2582021659696 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any.lock [DEBUG _api:172]
481 Attempting to acquire lock 2582021661808 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any.lock [DEBUG _api:172]
482 Lock 2582021659696 acquired on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any.lock [DEBUG _api:176]
482 Lock 2582021661808 acquired on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any.lock [DEBUG _api:176]
482 Attempting to acquire lock 2582021662816 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any.lock [DEBUG _api:172]
483 Attempting to release lock 2582021659696 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any.lock [DEBUG _api:209]
483 Attempting to release lock 2582021661808 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any.lock [DEBUG _api:209]
483 Lock 2582021662816 acquired on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any.lock [DEBUG _api:176]
484 Lock 2582021659696 released on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any.lock [DEBUG _api:212]
484 Lock 2582021661808 released on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any.lock [DEBUG _api:212]
485 Attempting to release lock 2582021662816 on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any.lock [DEBUG _api:209]
485 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any\pip to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\pip [DEBUG _sync:36]
486 Lock 2582021662816 released on C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any.lock [DEBUG _api:212]
486 copy C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\distutils-precedence.pth to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\distutils-precedence.pth [DEBUG _sync:36]
487 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any\wheel to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\wheel [DEBUG _sync:36]
488 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\pkg_resources to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\pkg_resources [DEBUG _sync:36]
520 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any\wheel-0.37.1.dist-info to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\wheel-0.37.1.dist-info [DEBUG _sync:36]
531 copy C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\wheel-0.37.1-py2.py3-none-any\wheel-0.37.1.virtualenv to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\wheel-0.37.1.virtualenv [DEBUG _sync:36]
540 generated console scripts wheel.exe wheel3.10.exe wheel3.exe wheel-3.10.exe [DEBUG base:41]
567 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\setuptools to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\setuptools [DEBUG _sync:36]
814 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\setuptools-65.3.0.dist-info to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\setuptools-65.3.0.dist-info [DEBUG _sync:36]
825 copy C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\setuptools-65.3.0.virtualenv to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\setuptools-65.3.0.virtualenv [DEBUG _sync:36]
826 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\setuptools-65.3.0-py3-none-any\_distutils_hack to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\_distutils_hack [DEBUG _sync:36]
833 generated console scripts  [DEBUG base:41]
1118 copy directory C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any\pip-22.2.2.dist-info to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\pip-22.2.2.dist-info [DEBUG _sync:36]
1129 copy C:\Users\omerg\AppData\Local\pypa\virtualenv\wheel\3.10\image\1\CopyPipInstall\pip-22.2.2-py3-none-any\pip-22.2.2.virtualenv to C:\Users\omerg\Desktop\Ömer\venv\Lib\site-packages\pip-22.2.2.virtualenv [DEBUG _sync:36]
1135 generated console scripts pip.exe pip3.10.exe pip3.exe pip-3.10.exe [DEBUG base:41]
1136 add activators for Bash, Batch, Fish, Nushell, PowerShell, Python [INFO session:61]
1145 write C:\Users\omerg\Desktop\Ömer\venv\pyvenv.cfg [DEBUG pyenv_cfg:30]
1145    home = C:\Python310 [DEBUG pyenv_cfg:34]
1146    implementation = CPython [DEBUG pyenv_cfg:34]
1146    version_info = 3.10.0.final.0 [DEBUG pyenv_cfg:34]
1147    virtualenv = 20.16.5 [DEBUG pyenv_cfg:34]
1147    include-system-site-packages = false [DEBUG pyenv_cfg:34]
1147    base-prefix = C:\Python310 [DEBUG pyenv_cfg:34]
1148    base-exec-prefix = C:\Python310 [DEBUG pyenv_cfg:34]
1148    base-executable = C:\Python310\python.exe [DEBUG pyenv_cfg:34]
1149 created virtual environment CPython3.10.0.final.0-64 in 978ms
  creator CPython3Windows(dest=C:\Users\omerg\Desktop\Ömer\venv, 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\omerg\AppData\Local\pypa\virtualenv)
    added seed packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator [WARNING __main__:17]
@OmerFI OmerFI added the bug label Sep 10, 2022
@OmerFI
Copy link
Author

OmerFI commented Sep 10, 2022

@uranusjr said the following about the activate.bat file in Discord:

resim

@skewballfox
Copy link

skewballfox commented Oct 24, 2022

Note this also seems to be an issue powershell:

 C:\Users\<user>\<project>> .\.venv\Scripts\Activate.ps1 -Verbose                       
VERBOSE: Activation script is located in path: 'C:\Users\<user>\<project>\.venv\Scripts'              
VERBOSE: VenvExecDir Fullname: 'C:\Users\<user>\<project>\.venv\Scripts                               
VERBOSE: VenvExecDir Name: 'Scripts                                                                                     
VERBOSE: VenvDir not given as a parameter, using parent directory name as VenvDir.                                      
VERBOSE: VenvDir=C:\Users\<user>\<project>\.venv                                                      
VERBOSE: Given ConfigDir=C:\Users\<user>\<project>\.venv, obtain values in pyvenv.cfg                 
VERBOSE: File exists, parse key = value lines                                                                           
VERBOSE: Adding Key:                                                                                                    
'home'='C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_<instance>'         
VERBOSE: Adding Key: 'include-system-site-packages'='false'                                                             
VERBOSE: Adding Key: 'version'='3.10.7'                                                                                 
VERBOSE: Prompt not specified as argument to script, checking pyvenv.cfg value                                          
VERBOSE:   Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)                                                                                       
VERBOSE:   Got leaf-name of C:\Users\<user>\<project>\.venv='.venv'                                   
VERBOSE: Prompt = '.venv'                                                                                               
VERBOSE: VenvDir='C:\Users\<user>\<project>\.venv'                                                   
VERBOSE: Setting prompt to '.venv'                                                                                      
(.venv) PS C:\Users\<user>\<project>> echo $PATH                                                      
(.venv) PS C:\Users\<user>\<project>> echo $VIRTUAL_ENV                                               
(.venv) PS C:\Users\<user>\<project>> echo $HOME                                                      
C:\Users\<user>                                                                                                         

this was causing an issue where pip was failing to install any c++ dependencies because of an incorrect include path.
ps that unterminated string was part of the output, not a formatting issue

@gaborbernat
Copy link
Contributor

PR welcome.

@jowodo
Copy link

jowodo commented Nov 22, 2023

Hi,

I'm on a Windows 10+powershell+python from Microsoft Store and I have the same behavior.

@pfmoore
Copy link
Member

pfmoore commented Nov 22, 2023

Powershell syntax for displaying an environment variable is echo $env:PATH. You missed out the env:.

@jowodo
Copy link

jowodo commented Nov 24, 2023

@pfmoore true, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@gaborbernat @pfmoore @skewballfox @OmerFI @jowodo and others