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

Pipenv on Windows Doesn't Locate the Python Executable Inside the Virtual Environment #6333

Open
georgi-gstellar opened this issue Jan 8, 2025 · 0 comments
Labels
OS: Windows This issue affects the Windows Operating System.

Comments

@georgi-gstellar
Copy link

Issue description

I'm running pipenv on a Windows 10 Pro machine and it looks like it's looking for the python executable in the root of the virtualenv instead of the Scripts folder inside the virtualenv root folder.

Running python -m pipenv install or python -m pipenv lock results in RuntimeError: Failed to lock Pipfile.lock!.
Running it in a verbose mode with python -m pipenv lock --verbose gives a little bit more info. Here's part of the stack trace (full stack trace below):

....
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 203, in base_paths
    paths = self.get_include_path()Error: Failed to lock Pipfile.lock!` and `FileNotFoundError: [WinError 2] The system cannot find the file specified` as described above.

  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 422, in get_include_path
    c = subprocess_run(command)
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\utils\processes.py", line 72, in subprocess_run
    return subprocess.run(
           ~~~~~~~~~~~~~~^
        args, text=text, encoding=encoding, check=False, **other_kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "subprocess.py", line 554, in run
  File "subprocess.py", line 1036, in __init__
  File "subprocess.py", line 1548, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
Locking Failed!
Full stack trace
Traceback (most recent call last):
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 183, in base_paths
    paths = self.get_paths()
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 342, in get_paths
    c = subprocess_run(command)
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\utils\processes.py", line 72, in subprocess_run
    return subprocess.run(
           ~~~~~~~~~~~~~~^
        args, text=text, encoding=encoding, check=False, **other_kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "subprocess.py", line 554, in run
  File "subprocess.py", line 1036, in __init__
  File "subprocess.py", line 1548, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 196, in base_paths
    paths = self._replace_parent_version(
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        paths, current_version
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 138, in
_replace_parent_version
    self.python_info.get("py_version_short", get_python_version()),
    ^^^^^^^^^^^^^^^^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 117, in python_info
    include_dirs = self.get_include_path()
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 422, in get_include_path
    c = subprocess_run(command)
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\utils\processes.py", line 72, in subprocess_run
    return subprocess.run(
           ~~~~~~~~~~~~~~^
        args, text=text, encoding=encoding, check=False, **other_kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "subprocess.py", line 554, in run
  File "subprocess.py", line 1036, in __init__
  File "subprocess.py", line 1548, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\resolver.py", line 466, in <module>
    main()
    ~~~~^^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\resolver.py", line 452, in main
    _main(
    ~~~~~^
        parsed.pre,
        ^^^^^^^^^^^
    ...<7 lines>...
        category=parsed.category,
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\resolver.py", line 436, in _main
    resolve_packages(
    ~~~~~~~~~~~~~~~~^
        pre, clear, verbose, system, write, requirements_dir, packages, category
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\resolver.py", line 413, in resolve_packages
    processed_results = process_resolver_results(
        results, resolver, project, pipfile_category
    )
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\resolver.py", line 323, in
process_resolver_results
    reverse_deps = project.environment.reverse_dependencies()
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 688, in
reverse_dependencies
    for req in self.get_package_requirements():
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 645, in
get_package_requirements
    packages = self.get_installed_packages()
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 549, in
get_installed_packages
    if self.dist_is_in_project(pkg) and normalized_name(pkg) != "python"
       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 530, in dist_is_in_project
    libdirs = self.base_paths["libdirs"]
              ^^^^^^^^^^^^^^^
  File "functools.py", line 1039, in __get__
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 203, in base_paths
    paths = self.get_include_path()
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\environment.py", line 422, in get_include_path
    c = subprocess_run(command)
  File "C:\Users\wssuser.db2\AppData\Roaming\Python\Python313\site-packages\pipenv\utils\processes.py", line 72, in subprocess_run
    return subprocess.run(
           ~~~~~~~~~~~~~~^
        args, text=text, encoding=encoding, check=False, **other_kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "subprocess.py", line 554, in run
  File "subprocess.py", line 1036, in __init__
  File "subprocess.py", line 1548, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

I investigated a little bit more inside pipenv\utils\processes.py and pipenv\environment.py and it seems the issue is due to pipenv trying to call the python executable directly in the root of the virtual environment instead of looking in the Scripts subfolder.
I printed the args inside subprocess_run in pipenv\utils\processes.py to confirm this. From the definition of the python method in environment.py it also seems like on Windows ("nt") the path is build by appending "python" to the prefix.

I copied the python executable from the Scripts folder to the root of the virtual environment and it seems to fix the issue, so I used this both to confirm that this is what's happening and also as a workaround.

I also tested without any dependencies in the Pipfile to confirm that its not related to any of those.

I'm using Mac to develop this project and also in general and haven't used Windows for a long time, so I'm not sure where the issue comes from. Is it standard to have the python in the Scripts subfolder? In this case maybe we should either update environment.py to use it or at least provide an option to override the path with an environment variable. Or else if the python executable was supposed to be in the root of the venv then we should see why it was not created there.

I'm happy to try and provide a fix or investigate more if we align on the approach.

Expected result

python -m pipenv lock runs without errors on Windows and finds the correct executable.

Actual result

We get the RuntimeError: Failed to lock Pipfile.lock! and FileNotFoundError: [WinError 2] The system cannot find the file specified as described above.

Steps to replicate

Running everything on a Windows 10 Pro machine.

  1. Download the embedded python 3.13 executable from the official website
  2. Install pip using get-pip.py
  3. Install pipenv using python -m pip install pipenv
  4. Run python -m pipenv lock

$ pipenv --support

Pipenv version: '2024.4.0'

Pipenv location: 'C:\\Users\\wssuser.db2\\AppData\\Roaming\\Python\\Python313\\site-packages\\pipenv'

Python location: 'D:\\utils\\python\\python.exe'

OS Name: 'nt'

User pip version: '24.3.1'

user Python installations found:

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.13.1',
 'os_name': 'nt',
 'platform_machine': 'AMD64',
 'platform_python_implementation': 'CPython',
 'platform_release': '10',
 'platform_system': 'Windows',
 'platform_version': '10.0.19045',
 'python_full_version': '3.13.1',
 'python_version': '3.13',
 'sys_platform': 'win32'}

System environment variables:

  • ACLOCAL_PATH
  • ALLUSERSPROFILE
  • APPDATA
  • CLIENTNAME
  • COMMONPROGRAMFILES
  • COMPUTERNAME
  • COMSPEC
  • CONFIG_SITE
  • COMMONPROGRAMFILES(X86)
  • COMMONPROGRAMW6432
  • DISPLAY
  • DRIVERDATA
  • EXEPATH
  • HOME
  • HOMEDRIVE
  • HOMEPATH
  • HOSTNAME
  • INFOPATH
  • LC_CTYPE
  • LOCALAPPDATA
  • LOGONSERVER
  • MANPATH
  • MINGW_CHOST
  • MINGW_PACKAGE_PREFIX
  • MINGW_PREFIX
  • MSYSTEM
  • MSYSTEM_CARCH
  • MSYSTEM_CHOST
  • MSYSTEM_PREFIX
  • NUMBER_OF_PROCESSORS
  • OLDPWD
  • ORIGINAL_PATH
  • ORIGINAL_TEMP
  • ORIGINAL_TMP
  • OS
  • ONEDRIVE
  • PATH
  • PATHEXT
  • PKG_CONFIG_PATH
  • PKG_CONFIG_SYSTEM_INCLUDE_PATH
  • PKG_CONFIG_SYSTEM_LIBRARY_PATH
  • PLINK_PROTOCOL
  • PROCESSOR_ARCHITECTURE
  • PROCESSOR_IDENTIFIER
  • PROCESSOR_LEVEL
  • PROCESSOR_REVISION
  • PROGRAMFILES
  • PS1
  • PSMODULEPATH
  • PUBLIC
  • PWD
  • PROGRAMDATA
  • PROGRAMFILES(X86)
  • PROGRAMW6432
  • SESSIONNAME
  • SHELL
  • SHLVL
  • SSH_ASKPASS
  • SYSTEMDRIVE
  • SYSTEMROOT
  • TEMP
  • TERM
  • TERM_PROGRAM
  • TERM_PROGRAM_VERSION
  • TMP
  • TMPDIR
  • USERDOMAIN
  • USERDOMAIN_ROAMINGPROFILE
  • USERNAME
  • USERPROFILE
  • WINDIR
  • _
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenvûspecific environment variables:

Debugûspecific environment variables:

  • PATH: C:\Users\wssuser.db2\bin;D:\utils\git\mingw64\bin;D:\utils\git\usr\local\bin;D:\utils\git\usr\bin;D:\utils\git\usr\bin;D:\utils\git\mingw64\bin;D:\utils\git\usr\bin;C:\Users\wssuser.db2\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\wssuser.db2\AppData\Local\Microsoft\WindowsApps;D:\utils\python;D:\utils\git\usr\bin\vendor_perl;D:\utils\git\usr\bin\core_perl
  • SHELL: D:\utils\git\usr\bin\bash.exe
  • PWD: D:/utils/project

Contents of Pipfile ('D:\utils\project\Pipfile'):

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pytest = "*"


[dev-packages]

[requires]
python_version = "3.13"
@oz123 oz123 added the OS: Windows This issue affects the Windows Operating System. label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS: Windows This issue affects the Windows Operating System.
Projects
None yet
Development

No branches or pull requests

2 participants