Pyenv python 管理无法正常工作?

Pyenv python 管理无法正常工作?

我使用的是 Ubuntu 18.04,默认安装了 python 2.7.17 和 python 3.6.9

我将有需要较新 Python 版本的项目,并且我知道安装和使用系统范围的 Python 版本可能会导致一些麻烦(已经这样做了,在使用切换版本时会导致麻烦update-alternatives

所以,我目前正在尝试使用pyenv

看起来安装成功了

$ pyenv --version
pyenv 2.3.4

然后我将 python 3.10.7 安装到 pyenv 中,看起来也成功了

$ pyenv versions
* system (set by /home/myuser/.pyenv/version)
  3.10.7

然后我尝试过使用 pyenv 创建虚拟环境在一个项目中对其进行测试,当我浏览生成的virtualenv目录时,我可以看到一些像这样的文件

$ ls -l
total 40
-rw-r--r-- 1 myuser myuser 2041 oct.   7 16:28 activate
-rw-r--r-- 1 myuser myuser  967 oct.   7 16:28 activate.csh
-rw-r--r-- 1 myuser myuser 2109 oct.   7 16:28 activate.fish
-rw-r--r-- 1 myuser myuser 9033 oct.   7 16:28 Activate.ps1
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip3
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip3.10
-rwxrwxr-x 1 myuser myuser  128 oct.   7 16:28 pydoc
lrwxrwxrwx 1 myuser myuser   10 oct.   7 16:28 python -> python3.10
lrwxrwxrwx 1 myuser myuser   10 oct.   7 16:28 python3 -> python3.10
lrwxrwxrwx 1 myuser myuser   52 oct.   7 16:28 python3.10 -> /home/myuser/.pyenv/versions/3.10.7/bin/python3.10

()但是,在激活虚拟环境的情况下(它在命令提示符之前显示虚拟环境的名称),pip似乎无法按预期运行。使用pip install -r requirements.txt尝试使用 python 2.7.17 pip,但由于版本问题而失败,使用pip3 install -r requirements.txt使用 python 3.6.9 pip,这不是我想要做的

Collecting orjson<4.0.0,>=3.2.1; extra == "all" (from fastapi[all]->-r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/92/97/895dfe0c2e7820fd5453d0efab6a9036de7f97b4edfd157a6a414dd3b0ee/orjson-3.6.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-8hgeru6w/orjson/setup.py'

我甚至不知道这些包是否已经在全球范围内安装在某个地方,因为我在任何地方都看不到它们……这就是我试图安装的

fastapi[all]
python-jose[cryptography]
passlib[bcrypt]

回到正题:使用pippython命令时,调用的可执行文件不是正确的

$ which python3
/usr/bin/python3

$ pyenv which python3
/home/myuser/.pyenv/versions/myproject/bin/python3

$ which pip3
/usr/bin/pip3

$ pyenv which pip3
/home/myuser/.pyenv/versions/myproject/bin/pip3

我已经核实过我的是否PATH正确,如果我的垫片已经准备好,他们

$ echo $PATH
/home/myuser/.pyenv/plugins/pyenv-virtualenv/shims:/home/myuser/.pyenv/bin:/home/myuser/.local/bin:/home/myuser/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/maven/bin:/usr/lib/android-sdk/tools:/usr/lib/android-sdk/platform-tools:/usr/lib/android-sdk/emulator:/usr/lib/android-sdk/tools/bin

$ pyenv shims
/home/myuser/.pyenv/shims/2to3
/home/myuser/.pyenv/shims/2to3-3.10
/home/myuser/.pyenv/shims/activate
/home/myuser/.pyenv/shims/activate.csh
/home/myuser/.pyenv/shims/activate.fish
/home/myuser/.pyenv/shims/Activate.ps1
/home/myuser/.pyenv/shims/idle
/home/myuser/.pyenv/shims/idle3
/home/myuser/.pyenv/shims/idle3.10
/home/myuser/.pyenv/shims/pip
/home/myuser/.pyenv/shims/pip3
/home/myuser/.pyenv/shims/pip3.10
/home/myuser/.pyenv/shims/pydoc
/home/myuser/.pyenv/shims/pydoc3
/home/myuser/.pyenv/shims/pydoc3.10
/home/myuser/.pyenv/shims/python
/home/myuser/.pyenv/shims/python3
/home/myuser/.pyenv/shims/python3.10
/home/myuser/.pyenv/shims/python3.10-config
/home/myuser/.pyenv/shims/python3.10-gdb.py
/home/myuser/.pyenv/shims/python3-config
/home/myuser/.pyenv/shims/python-config

我需要修改什么才能使pythonpip命令使用来自我的 pyenv 生成的虚拟环境的可执行文件?

相关内容