无法使用旧解释器设置 Python 环境

无法使用旧解释器设置 Python 环境

我已经virtualenvwrapper在 Arch Linux 上安装了平均房颤存储库python38,以便我可以设置环境并使用 TensorFlow。我已.bashrc按照通常的建议进行了设置文档我准备好了:

export PATH="$PATH:/home/myuser/.local/bin"

# Virtualenv custom folder
export WORKON_HOME=/home/myuser/development/venvs

# Remaining configurations
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
export VIRTUALENVWRAPPER_SCRIPT=/usr/bin/virtualenvwrapper.sh
source /usr/bin/virtualenvwrapper_lazy.sh

当调用mkvirtualenv test和时workon,venv 被正确构建和列出,并且可以正常访问。

但是,由于我希望能够安装 TensorFlow,因此我更改了变量PYTHON

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.8

但是现在,当我重新启动 shell 并尝试创建虚拟环境时,由于缺少包而发生错误。

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/myuser/.local/lib/python3.8/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
    from stevedore import ExtensionManager
  File "/home/myuser/.local/lib/python3.8/site-packages/stevedore/__init__.py", line 11, in <module>
    from .extension import ExtensionManager
  File "/home/myuser/.local/lib/python3.8/site-packages/stevedore/extension.py", line 17, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.8 and that PATH is
set properly.
created virtual environment CPython3.9.1.final.0-64 in 227ms
  creator CPython3Posix(dest=/home/myuser/development/venvs/testing, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/myuser/.local/share/virtualenv)
    added seed packages: pip==21.0.1, setuptools==52.0.0, wheel==0.36.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/myuser/.local/lib/python3.8/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
    from stevedore import ExtensionManager
  File "/home/myuser/.local/lib/python3.8/site-packages/stevedore/__init__.py", line 11, in <module>
    from .extension import ExtensionManager
  File "/home/myuser/.local/lib/python3.8/site-packages/stevedore/extension.py", line 17, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

virtualenvwrapper我觉得这很奇怪,因为里面有一个文件夹/home/myuser/.local/lib/python3.8/site-packages(讽刺的是不是一个python3.9/site-packages),我无法手动安装它:

$ python3.8 -m pip install --user pkg_resources
/usr/bin/python3.8: No module named pip

这是怎么回事?老实说,这是我第三次或第四次尝试使用 venvs,但我找不到一个可靠的来源来解释我应该如何处理它们,而且每次都会有一些重大挫折让我放弃。=(


编辑:运行mkvirtualenv -p /usr/bin/python3.8 new_venv确实有效,但由于我只打算使用 venvs 来处理旧版本,因此我想将其直接设置为变量。

相关内容