pipenv Failing to Install Packages

Viewed 986

So this error happened after I uninstalled Python 3.7.4 for the newer Python 3.8.3. I try to use pipenv install and this is what it outputs:

PS C:\Users\enoch\Documents\spectral_curve_calculator> pipenv install
Traceback (most recent call last):
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 618, in parse_executable
    result_version = get_python_version(path)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\utils.py", line 105, in get_python_version      
    c = subprocess.Popen(version_cmd, **subprocess_kwargs)
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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\enoch\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Scripts\pipenv.exe\__main__.py", line 7, in <module>
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\cli\command.py", line 232, in install
    retcode = do_install(
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\core.py", line 1921, in do_install
    ensure_project(
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\core.py", line 576, in ensure_project
    ensure_virtualenv(
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\core.py", line 498, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\core.py", line 388, in ensure_python
    path_to_python = find_a_system_python(python)
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\core.py", line 350, in find_a_system_python
    return next(iter(finder.find_all_python_versions()), None)
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 312, in find_all_python_versions
    python_version_dict = getattr(self.system_path, "python_version_dict", {})
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 120, in system_path
    self._system_path = self.create_system_path()
  File "c:\users\enoch\appdata\local\programs\python\python38\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 82, in create_system_path
    return pyfinder_path.SystemPath.create(
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 682, in create
    instance = instance._run_setup()
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 233, in _run_setup
    new_instance = new_instance._setup_windows()
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 411, in _setup_windows
    windows_finder = WindowsFinder.create()
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\windows.py", line 146, in create
    return cls()
  File "<attrs generated init pythonfinder.models.windows.WindowsFinder>", line 13, in __init__
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\windows.py", line 113, in get_versions
    versions[py_version.version_tuple[:5]] = base_dir
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 365, in __getattribute__
    result = super(PythonVersion, self).__getattribute__(key)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 430, in version_tuple
    self.patch,
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 375, in __getattribute__
    instance_dict = self.parse_executable(executable)
  File "C:\Users\enoch\AppData\Local\Programs\Python\Python38\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 620, in parse_executable
    raise ValueError("Not a valid python path: %r" % path)
ValueError: Not a valid python path: 'C:/Users/enoch/Downloads/WPy64-3741/python-3.7.4.amd64/Scripts/python.exe'

So it seems that the issue happens since it is still trying to reference my old python location even though I already uninstalled it: ValueError: Not a valid python path: 'C:/Users/enoch/Downloads/WPy64-3741/python-3.7.4.amd64/Scripts/python.exe' I checked my environment variables and paths through control panel; they all point to my new Python 3.8.3 installation. Printing sys.path, it also never mentions the path of my previous installation. Does anyone have any idea of what's going on? Thank you!

3 Answers

I got the same problem. You can try to go to regedit, and find the key word "python-3.7.4", delete all of them, and retry.

Met the exact same error.
Ultimately, I solved this problem by simply deleting the duplicate python version using control panel.
But since you have already deleted the older version, then here is what I have been through, hope it would help.


Python.py

Since the traceback is all about a wrong path, I followed the error message and dug into this pythonfinder\models\python.py file.
In there I found a method called parse_executable(cls, path).
I threw a print(path) in and it seems that the path variable was printed twice.

  • One for the normal python in my PATH.
  • Another for the old python path, python2.x, even it is not in my PATH variable

I play around with this file for a while, trying to figure out how the path is created and why it includes the zombie python2.x version that's not even a valid python path.

Though barely understand the logic, I thought what happened would be like:

  • parse_executable() > python 3.8 >
  • check another version > parse_executable() > python 2.x > traceback

Registries

In order to solve the problem, I started to browse the internet. And this blog pointed out how the registry could come into play.

I followed this answer and found the registries related to python in my machine are completely wrong. My python version should be 3.8, but it is 2.x

enter image description here

So I deleted all the python. registries. The data in them is wrong.

enter image description here

This may not be recommended and I am sorry I can't explain this well. Because I just thought this could be related without considering how important the registries are... You can refer to this post to find out how to do.

Desperate shots

After that, pipenv was still not working. And this parse_executable(cls, path) still printed two paths. I tried a lot to make sure that the python2.x was not in any possible paths.

  • I deleted {user}\AppData\Local\Programs\Python folder.
  • I deleted {user}\AppData\Local\Roaming\Python37 folder.(I didn't know it exists...)

But still, python2.x was considered by python.py.

After all the struggling, I figured maybe this is not the issue about path, but the existing of a program. So I uninstalled the python2.x version in my machine. Surprisingly this desperate shot worked at last.

In short, I think the problem is incompletely uninstall the older python version, which may include the registries. I hope this could provide you a hint of why this error happened and how to solve it completely.

ps: I am still curious about how python.py could find the version of python2.x which is not in any environment variables.

I hope this could save someone's time.
My machine OS is Windows 10. I had the same problem, and the problem was caused by renamed executable, namely python.exe was named as python2.exe. The module python.py looks for python.exe in default locations, and after not finding it there raises the exception. So the solution in my case was to change the name to python.exe.

To see the default location of each python version use the following code:

>>> import os
>>> import sys
>>> print(os.path.dirname(sys.executable))

If you're curious about how I figured that out. Look inside the python.py, the following code determines that very path('C:/Users/enoch/Downloads/WPy64-3741/python-3.7.4.amd64/Scripts/python.exe') which is displayed in the error messages:

def from_windows_launcher(cls, launcher_entry, name=None, company=None):
        ...
        default_path = base_path / "python.exe"
        if not default_path.exists():
            default_path = base_path / "Scripts" / "python.exe"

As you can see it looks for python.exe and in my case it was named as python2.exe.

Related