【问题标题】:trying to create a virtual environment尝试创建虚拟环境
【发布时间】:2021-05-01 16:12:53
【问题描述】:

我在正确目录中的 powershell 中键入了“pipenv install”,现在它给了我一个巨大的错误消息,我认为这与我的 python 路径有关。错误信息如下所示。

我的 sys.path 列表是:

'c:\Users\f l a s h\Documents\pythonfile',
'C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\python39.zip',
'C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\DLLs',
'C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\lib',
'C:\Users\f l a s h\AppData\Local\Programs\Python\Python39',
'C:\Users\f l a s h\AppData\Roaming\Python\Python39\site-packages',
'C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\lib\site-packages'

我需要这个,因为我打算用它来学习 django。任何关于这是什么或如何解决它的帮助都会很棒。

PS C:\Users\f l a s h\Dev\cfehome> pipenv install
Traceback (most recent call last):
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 618, in parse_executable
    result_version = get_python_version(path)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\utils.py", line 105, in get_python_version
    c = subprocess.Popen(version_cmd, **subprocess_kwargs)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\subprocess.py", line 1416, 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\f l a s h\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Scripts\pipenv.exe\__main__.py", line 7, in <module>
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\cli\command.py", line 233, in install
    retcode = do_install(
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 1920, in do_install
    ensure_project(
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 576, in ensure_project
    ensure_virtualenv(
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 498, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 388, in ensure_python
    path_to_python = find_a_system_python(python)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\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\f l a s h\appdata\local\programs\python\python39\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\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 120, in system_path
    self._system_path = self.create_system_path()
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 82, in create_system_path
    return pyfinder_path.SystemPath.create(
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 682, in create
    instance = instance._run_setup()
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 233, in _run_setup
    new_instance = new_instance._setup_windows()
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\path.py", line 411, in _setup_windows
    windows_finder = WindowsFinder.create()
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\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\f l a s h\AppData\Local\Programs\Python\Python39\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\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 365, in __getattribute__
    result = super(PythonVersion, self).__getattribute__(key)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 430, in version_tuple
    self.patch,
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 375, in __getattribute__
    instance_dict = self.parse_executable(executable)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\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/f l a s h/anaconda3/python.exe'
PS C:\Users\f l a s h\Dev\cfehome> pipenv --python 3.9
Traceback (most recent call last):
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 618, in parse_executable
    result_version = get_python_version(path)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\utils.py", line 105, in get_python_version
    c = subprocess.Popen(version_cmd, **subprocess_kwargs)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\subprocess.py", line 1416, 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\f l a s h\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Scripts\pipenv.exe\__main__.py", line 7, in <module>
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 1236, in invoke
    return Command.invoke(self, ctx)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\f l a s h\AppData\Local\Programs\Python\Python39\Lib\site-packages\pipenv\vendor\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\cli\command.py", line 199, in cli
    ensure_project(
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 576, in ensure_project
    ensure_virtualenv(
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 498, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 388, in ensure_python
    path_to_python = find_a_system_python(python)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\core.py", line 354, in find_a_system_python
    python_entry = find_python(finder, line)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\utils.py", line 2213, in find_python
    result = finder.find_python_version(line)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 276, in find_python_version
    if os.name == "nt" and self.windows_finder is not None:
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 129, in windows_finder
    self._windows_finder = WindowsFinder()
  File "<attrs generated init pipenv.vendor.pythonfinder.models.windows.WindowsFinder>", line 13, in __init__
  File "c:\users\f l a s h\appdata\local\programs\python\python39\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\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 365, in __getattribute__
    result = super(PythonVersion, self).__getattribute__(key)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 430, in version_tuple
    self.patch,
  File "c:\users\f l a s h\appdata\local\programs\python\python39\lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 375, in __getattribute__
    instance_dict = self.parse_executable(executable)
  File "c:\users\f l a s h\appdata\local\programs\python\python39\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/f l a s h/anaconda3/python.exe'

【问题讨论】:

标签: python pip path virtual-environment


【解决方案1】:

如果您尝试安装 pipenv:

$ pip install --user pipenv

如果您尝试使用 pipenv 安装软件包:

$ cd myproject
$ pipenv install <package_name>

docs.pipenv.org

但是根据你日志的最后一行:

ValueError: Not a valid python path: 'C:/Users/f l a s h/anaconda3/python.exe'

您已经安装了 anaconda3 并且您正在从那里使用 python.exe。考虑到 pipenv 和 anaconda3 是创建环境的不同方式,它们不一定兼容。

如果你打算使用 Anaconda3,你可以使用 'conda' 命令来安装你的包。

$ conda install <package_name>

Conda Managing environments

Conda cheatsheet

如果您打算为您的项目使用 pipenv,您可以检查您的 PATH 环境变量以查看您从哪里调用 python 可执行文件并将其更改为使用您本地自己安装的 python 而不是 Anaconda3 python。

【讨论】:

    【解决方案2】:

    您可能在注册表中有一些以前安装的 python 的过时条目。

    看到这个: https://github.com/pypa/pipenv/issues/4334

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 2021-07-30
      • 2018-06-18
      • 2018-01-29
      • 2020-11-19
      • 2020-08-19
      相关资源
      最近更新 更多