pipenv无法安装软件包

时间:2020-06-07 03:55:15

标签: python python-3.x pipenv pythonpath

因此,当我为较新的Python 3.8.3卸载Python 3.7.4之后,发生了此错误。我尝试使用pipenv install,这是它的输出:

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'

所以似乎发生了这个问题,因为即使我已经卸载了它,它仍然试图引用我的旧python位置:ValueError: Not a valid python path: 'C:/Users/enoch/Downloads/WPy64-3741/python-3.7.4.amd64/Scripts/python.exe'我通过控制面板检查了环境变量和路径;它们都指向我的新Python 3.8.3安装。打印sys.path时,它也从未提及我先前安装的路径。有谁知道发生了什么吗?谢谢!

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。 您可以尝试去regedit,找到关键词“ python-3.7.4”,删除所有关键词,然后重试。

答案 1 :(得分:1)

遇到完全相同的错误。
最终,我通过使用控制面板简单地删除重复的 python 版本解决了这个问题。
但既然你已经删除了旧版本,那么我的经历就是这样,希望对你有所帮助。


Python.py

由于回溯完全是关于错误的路径,我按照错误消息并深入研究了这个 pythonfinder\models\python.py 文件。
在那里我找到了一个名为 parse_executable(cls, path) 的方法。
我扔了一个 print(path),似乎 path 变量被打印了两次。

  • 一个用于我的 PATH 中的普通 python。
  • 另一个用于旧的 python 路径,python2.x,即使它不在我的 PATH 变量中

我玩了一会儿这个文件,试图弄清楚 path 是如何创建的,以及为什么它包含了僵尸 python2.x 版本,它甚至不是一个有效的 python 路径。

虽然几乎不明白逻辑,但我认为发生的事情会是这样的:

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

注册表

为了解决这个问题,我开始上网。 this 博客指出了注册表如何发挥作用。

我按照这个答案,发现我机器中与python相关的注册表是完全错误的。我的python版本应该是3.8,但它是2.x

enter image description here

所以我删除了所有 python. 注册表。里面的数据是错误的。

enter image description here

这可能不被推荐,很抱歉我无法很好地解释这一点。因为我只是认为这可能是相关的,而没有考虑注册表的重要性...您可以参考 this 帖子了解如何操作。

绝望的镜头

在那之后,pipenv 仍然无法正常工作。而这个 parse_executable(cls, path) 仍然打印了两条路径。我尝试了很多以确保 python2.x 不在任何可能的路径中。

  • 我删除了 {user}\AppData\Local\Programs\Python 个文件夹。
  • 我删除了 {user}\AppData\Local\Roaming\Python37 个文件夹。(我不知道它存在...)

不过,python2.x 还是被 python.py 考虑了。

经过一番苦苦挣扎,我想这可能不是路径的问题,而是程序存在的问题。所以我在我的机器上卸载了python2.x版本。令人惊讶的是,这个绝望的镜头终于奏效了。

简而言之,我认为问题是未完全卸载较旧的python版本,其中可能包括注册表。我希望这可以为您提供为什么会发生此错误以及如何彻底解决此错误的提示。

ps:我还是很好奇python.py如何找到不在任何环境变量中的python2.x版本。