在AWS上更新我的一台Ubuntu 16.04计算机后,python / pip似乎已损坏。
ubuntu@host:~$ pip install celery
Traceback (most recent call last):
File "/home/ubuntu/virtualenvs/myenv/bin/pip", line 7, in <module>
from pip import main
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/__init__.py", line 43, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
ubuntu@host:~$ python3.6 -m pip install celery
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/__init__.py", line 43, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/site-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
File "/home/ubuntu/virtualenvs/myenv/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
系统运行通过jonathonf/python-3.6
ppa安装的python3.6。在系统更新(apt-get update && apt-get upgrade
)之前,一切都按预期工作。我还在其他尚未更新的机器上验证了这一点。
我还没有在新机器上的虚拟环境中安装python3.6的运气,所以我猜最近的版本或更新在这里打破了什么?
编辑:
在新的ubuntu上安装时,我也遇到了类似的问题:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo add-apt-repository jonathonf/python-3.6
$ sudo apt-get update
$ sudo apt-get install python3.6
$ stat /usr/lib/python3.6/distutils/dist.py
stat: cannot stat '/usr/lib/python3.6/distutils/dist.py': No such file or directory
$ ll /usr/lib/python3.6/distutils/
total 36
drwxr-xr-x 2 root root 4096 May 3 15:55 ./
drwxr-xr-x 28 root root 12288 May 3 15:44 ../
-rw-r--r-- 1 root root 236 May 3 11:50 __init__.py
-rw-r--r-- 1 root root 12345 May 3 11:50 version.py
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
答案 0 :(得分:2)
我在一个新的docker容器中测试了PPA,看起来包坏了,安装后缺少所有distutils
个模块。看起来最近重建了包裹;也许这是一个新问题。
You can open a bug并等到PPA维护者修复它,但除此之外,你无能为力。你当然可以尝试摆弄安装:
$ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
$ tar xvf Python-3.6.5.tgz
$ rsync -av Python-3.6.5/Lib/distutils/ /usr/lib/python3.6/distutils/
当然,这是一个非常脏的东西,因为我不知道哪个文件应该来自PPA的正确包。因此,我无法保证这对您是否有效并且不会引入任何新错误,但至少我可以再次运行pip
并安装一个软件包。
答案 1 :(得分:2)
你确实没有疯狂,同样的问题在这里。
你也可以从同一个ppa尝试以前版本的ppa,直到他们修复它: https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.6
示例命令行是:
apt-get install python3.6=3.6.3-1ubuntu1~17.04.york1
答案 2 :(得分:2)
这解决了我在Ubuntu和Linux Mint上遇到的问题。首先通过运行命令确认python3.6
是通过ppa:jonathonf/python-3.6
安装的:
ls /etc/apt/sources.list.d
sudo rm -i /etc/apt/sources.list.d/jonathonf-python-3_6-xenial.list
然后使用以下内容添加deadsnakes
PPA
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
最后删除/安装或重新安装python3.6
sudo apt-get remove python3.6
sudo apt-get install python3.6
重新安装python时,我也遇到了未满足的依赖项。通过手动删除libpython3.6-minimal
解决了这个问题。希望这有帮助!
答案 3 :(得分:0)
运行
sudo apt update && sudo apt install -f && sudo apt upgrade
sudo apt-get install python3.6
克服安装失败的问题
答案 4 :(得分:0)
您可以尝试以下方法:
document.write()
您将获得一个依赖项列表,并将其全部添加到此行的末尾:
# dpkg -l | grep python3.5
现在运行此:
# apt-get --purge remove <here>
这是一篇不错的文章的链接:https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
答案 5 :(得分:0)
我刚升级到迪斯科野狗(19.04),它破坏了我的python3.6,并显示以下错误消息:
tox -e py36 --recreate
...
Traceback (most recent call last):
File "/home/pierre/.local/lib/python3.7/site-packages/virtualenv.py", line 22, in <module>
import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'
Running virtualenv with interpreter /usr/bin/python3.6
您可以切换到Python 3.7,它似乎是新的默认设置:tox -e py37
运行正常。