将pip版本升级到10.0.0后,当与安装的distutils包发生版本冲突时,使用pip的安装将失败:
Cannot uninstall '***'. 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.这可能是为了PyYAML, pyOpenSSL, urllib3, chardet等等。
我试图通过卸载相应的软件包来管理这个问题,例如;
python-yaml python-openssl python-urllib3 python-chardet使用apt-get (Ubuntu),然后再用pip安装这些库
但是,正如可能预期的那样,apt-get的删除还会导致删除许多依赖的附加系统包,这似乎不是一个好做法:
The following packages will be REMOVED:
apt-xapian-index cloud-init landscape-client-ui-install oneconf python-aptdaemon python-aptdaemon.gtk3widgets python-chardet python-cupshelpers python-debian python-openssl python-pip python-requests python-ubuntu-sso-client python-urllib3 python-yaml sessioninstaller software-center ssh-import-id system-config-printer-common system-config-printer-gnome system-config-printer-udev ubuntu-desktop ubuntu-release-upgrader-gtk ubuntu-sso-client ubuntu-sso-client-qt update-manager update-notifier update-notifier-common我也不想将pip降级为旧版本。
那么,使用pip处理冲突的distutils库的最佳实践是什么呢?
Ps:我认为pip是为了方便地管理Python库,但这一事件使它变得足够复杂。
发布于 2018-04-20 09:57:38
Python的虚拟环境可能有助于处理冲突的库,即使使用较新版本的pip。
安装虚拟
Python3有内置的虚拟环境。在Python2的情况下,virtualenv可用于此目的。
使用以下命令设置virtualenv
sudo pip install virtualenv
venv_path="${HOME}/py_venv"
mkdir -p "${venv_path}"
virtualenv "${venv_path}"它可以通过source命令激活
source "${venv_path}/bin/activate"
(py_venv) my_user@my_machine:~$,并且可以通过deactivate命令停用
(py_venv) my_user@my_machine:~$ deactivate
my_user@my_machine:~$确认python和pip的路径
(py_venv) my_user@my_machine:~$ which python
/home/my_user/py_venv/bin/python
(py_venv) my_user@my_machine:~$ which pip
/home/my_user/py_venv/bin/pip请注意,默认情况下,使用sudo执行时不指向虚拟化
(py_venv) my_user@my_machine:~$ sudo which python
/usr/bin/python
(py_venv) my_user@my_machine:~$ sudo which pip
/usr/local/bin/pip用pip安装/卸载软件包
(py_venv) my_user@my_machine:~$ pip install ansible成功安装在virtualenv中
(py_venv) my_user@my_machine:~$ which ansible
/home/my_user/py_venv/bin/ansible在virtualenv中卸载冲突的系统包
(py_venv) my_user@my_machine:~$ pip uninstall urllib3
Skipping urllib3 as it is not installed.在实际环境中卸载相同的软件包
(py_venv) my_user@my_machine:~$ deactivate
my_user@my_machine:~$ pip uninstall urllib3
Cannot uninstall 'urllib3'. 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.可以看到,在Python虚拟环境的帮助下,可以使用较新版本的pip安装和卸载Python库,而无需接触任何系统包。
https://stackoverflow.com/questions/49916736
复制相似问题