【发布时间】:2019-12-14 05:50:07
【问题描述】:
我想通过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
我没有想到或在网络上找到的解决方案:
-
使用
rm -rf /usr/lib/python2.7/dist-packages/docutils*删除apt版本。这会使pip沉默,但意味着:- 系统上安装的文件不再符合 Debian 打包系统的想法
- 我可能会破坏系统软件对 docutils 0.14 的依赖关系
- 对 Debian 软件包的任何更新都会导致
apt重新安装 - this answer 中讨论的其他问题
pip install --force-reinstall。 (同样的问题。)-
pip install --ignore-install。 (同样的问题。)
有没有办法让默认环境适用于pip 的最新版本的东西,但不会破坏任何系统软件? The same answer above 建议使用virtualenv、venv、pyenv、pipenv 之一。我试过pipenv,它不想使用--system安装命令行中列出的单个包,我不知道创建Pipfile是否真的能解决这个问题。
我宁愿不用手动切换环境来使用apt-installed 包而不是pip-installed 包。有没有办法让 apt 安装的软件只使用一个环境,否则将环境与 pip 安装的东西一起使用?
【问题讨论】:
-
apt 安装的版本很可能被其他应用使用,或者更糟糕的系统,您应该尝试修改此安装。好的做法是并行拥有多个版本,这应该使用 virtualenv 或等效的来完成。注意:
pip install --user docutils可能有效,但我建议使用 virtualenv。
标签: python linux pip debian apt