这个问题很简单,因为 apt 安装的 pipenv 版本太老了,用最新的 pipenv 版本就好了,怎么获得最新的 pipenv 版本?直接用 pip 安装!

解决办法:

  • 方法一:使用自带的 pip 安装最新的 pipenv ,比如 ubuntu20 是自带的 pip3.8 可以安装,用命令 pip3 install pipenv 就好了
  • 方法二:使用自己编译安装的 python 带的 pipenv 就好了

ubutu20 自带的 python 解释器是 python3.8

╰─➤  lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal

我想安装一个 pipenv 来虚拟环 python3.10

python3.10 是通过源码自行编译安装的,参考:Ubuntu20.04 从源代码编译安装 python3.10

通过下面的代码安装 pipenv

sudo apt install pipenv

然后创建虚拟环境

pipenv install --python=/home/pon/opt/python/cpython/python3.10/bin/python3.10  

但是遇到了错误

╰─➤  pipenv install --python=/home/pon/opt/python/cpython/python3.10/bin/python3.10                                              130 ↵
Virtualenv already exists!
Removing existing virtualenv…
Creating a virtualenv for this project…
Using /home/pon/opt/python/cpython/python3.10/bin/python3.10 (3.10.7) to create virtualenv…
⠋created virtual environment CPython3.10.7.final.0-64 in 816ms
  creator CPython3Posix(dest=/home/pon/.local/share/virtualenvs/tracksource-XXsh2Vxq, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/pon/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Virtualenv location: /home/pon/.local/share/virtualenvs/tracksource-XXsh2Vxq
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
  from . import utils
  File "/usr/lib/python3/dist-packages/pipenv/vendor/requests/utils.py", line 27, in <module>
    from .cookies import RequestsCookieJar, cookiejar_from_dict
  File "/usr/lib/python3/dist-packages/pipenv/vendor/requests/cookies.py", line 172, in <module>
    class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'

解决办法还是什么呢?

使用 python3.10 安装 pipenv

~/opt/python/cpython/python3.10/bin/pip3.10 install pipenv

查看版本,可以看到时最新的

─➤  pipenv --version
pipenv, version 2022.10.10

用这个最新的 pipenv 就可以创建 python3.10 的虚拟环境了

pipenv install --python=/home/pon/opt/python/cpython/python3.10/bin/python3.10                                              130 ↵
Creating a virtualenv for this project...
Pipfile: /home/pon/code/pon/tracksource/Pipfile
Using /home/pon/opt/python/cpython/python3.10/bin/python3.10 (3.10.7) to create virtualenv...
⠴ Creating virtual environment...created virtual environment CPython3.10.7.final.0-64 in 799ms
  creator Venv(dest=/home/pon/.local/share/virtualenvs/tracksource-XXsh2Vxq, clear=False, no_vcs_ignore=False, global=False, describe=CPython3Posix)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/pon/.local/share/virtualenv)
    added seed packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

✔ Successfully created virtual environment! 
Virtualenv location: /home/pon/.local/share/virtualenvs/tracksource-XXsh2Vxq
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (fedbd2ab7afd84cf16f128af0619749267b62277b4cb6989ef16d4bef6e4eef2)!
Installing dependencies from Pipfile.lock (e4eef2)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

ubuntu20 apt 仓库中的 pipenv 有多老?

╰─➤  pipenv --version                                       >                       
pipenv, version 11.9.0

图片.png


所以这个问题告诉我们,对于命令行工具,尽可能用 pip 安装,而不是 Linux 发行版仓库中的版本


universe_king
3.4k 声望678 粉丝