python - 使用 pip 升级最初通过 apt 安装的包

标签 python linux pip debian apt

我想通过pip安装最新版本的docutils,但是不知道如何升级通过apt<安装的系统版本.

$ sudo --set-home python2 -m pip install --upgrade docutils
Collecting docutils
  Using cached https://files.pythonhosted.org/packages/3a/dc/bf2b15d1fa15a6f7a9e77a61b74ecbbae7258558fcda8ffc9a6638a6b327/docutils-0.15.2-py2-none-any.whl
Installing collected packages: docutils
  Found existing installation: docutils 0.14
ERROR: Cannot uninstall 'docutils'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

$ apt-cache show python-docutils | head -n 3
Package: python-docutils
Architecture: all
Version: 0.14+dfsg-3

我想过或在网上找到的解决方案都没有:

  1. 使用rm -rf/usr/lib/python2.7/dist-packages/docutils* 删除apt 版本。这会使 pip 静音,但意味着:

    • 系统上安装的文件不再符合 Debian 打包系统的想法
    • 我可能会打破系统软件对 docutils 0.14 的依赖
    • 对 Debian 软件包的任何更新都会导致 apt 重新安装
    • this answer中讨论的其他问题
  2. pip 安装 --force-reinstall。 (同样的问题。)

  3. pip install --ignore-install。 (同样的问题。)

有没有办法获得一个默认环境,该环境适用于 pip 的最新版本,但没有机会破坏任何系统软件? The same answer above建议使用 virtualenvvenvpyenvpipenv 之一。我尝试了 pipenv 并且它不想使用 --system 安装命令行上列出的单个包而且我不知道是否创建了 Pipfile实际上会解决这个问题。

我宁愿不必以某种方式手动切换环境来使用 apt 安装的软件包与 pip 安装的软件包。有没有一种方法可以只让安装了 apt 的软件使用一个环境,否则就可以使用安装了 pip 的东西的环境?

最佳答案

I would rather not have to manually switch environments somehow to use the apt-installed packages versus the pip-installed packages. Is there a way to get only apt-installed software to use one environment and otherwise use the environment with the pip-installed stuff?

理想情况下,应该使用系统版本 pip 版本。

根据 Debian Python Policy ,

As long as you don't install other versions of Python in your path, Debian's Python versions won't be affected by a new version.

If you install a different micro version of the version of Python you have got installed, you will need to be careful to install all the modules you use for that version of Python too.

关于python - 使用 pip 升级最初通过 apt 安装的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57380039/

相关文章:

python - 来自两个字符串列表的列表的组合

python - 如何在 FastAPI 的 CORS 中间件中正确使用正则表达式?

python - 使用 python-Scrapy 抓取动态内容

linux - 为什么我不能从/dev/snd/midi*读取数据?

linux - 您拥有 Archive::Tar 1.3901,但建议使用 1.50 或更高版本。请升级。问题

linux - 在 linux 上安装多个包(比如 pip install -r requirements.txt)

c++ - Python 不调用外部程序第 3 部分

linux - 如何在不连接它们的情况下计算 2 个字段中的唯一值?

python - pyvenv 安装了错误的 pip 版本

python - 如何解决在 virtualenv 中安装 python 包的错误?