我想通过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 安装 --force-reinstall
。 (同样的问题。)pip install --ignore-install
。 (同样的问题。)
有没有办法获得一个默认环境,该环境适用于 pip
的最新版本,但没有机会破坏任何系统软件? The same answer above建议使用 virtualenv
、venv
、pyenv
、pipenv
之一。我尝试了 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/