在 ubuntu 上将 python3.4 升级到 python3.6 会破坏 pip
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42558133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upgrading python3.4 to python3.6 on ubuntu breaks pip
提问by Alex Botev
I'm attempting to install python3.6 on my machine after I currently have python3.4. However, after installation trying to run pip
under python3.6 gives me the error:
在我目前拥有 python3.4 后,我试图在我的机器上安装 python3.6。但是,安装后尝试pip
在 python3.6 下运行给了我错误:
Traceback (most recent call last):
File "pip3", line 7, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 59, in <module>
from pip.log import logger
File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in <module>
import colorama, pkg_resources
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1520, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "pip3", line 7, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 59, in <module>
from pip.log import logger
File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in <module>
import colorama, pkg_resources
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1520, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
There were several comments on the internet about that error being encountered, However, none of them contain any actual resolution suggestion. Does anyone have any idea how I could fix this?
互联网上有几条关于遇到该错误的评论,但是,没有一条包含任何实际的解决建议。有谁知道我该如何解决这个问题?
回答by Vendii
I managed to solve it without installing anything from sources. Here's what I did:
我设法在没有从源代码安装任何东西的情况下解决了它。这是我所做的:
First, install
pip
for Python3.x (for some weird reason I didn't have it...)$ sudo apt-get install python3-pip
It is an old version...
$ pip3 --version pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)
... so upgradeit to the latest
$ sudo pip3 install --upgrade pip
Now it is much better
$ sudo pip3 --version pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
首先,
pip
为 Python3.x安装(出于某种奇怪的原因我没有它......)$ sudo apt-get install python3-pip
这是旧版本...
$ pip3 --version pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)
...所以将其升级到最新版本
$ sudo pip3 install --upgrade pip
现在好多了
$ sudo pip3 --version pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
Then upgrade
virtualenvvwrapper
$ sudo pip3 install --upgrade virtualenvwrapper # ... Successfully installed pbr-3.0.1 six-1.10.0 stevedore-1.22.0 virtualenv-15.1.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.7.2
Now creating a new virtualenv works:
$ mkvirtualenv -p `which python3.6` <VIRTUALENV_NAME>
pip
also works:$ pip install django # ... Successfully installed django-1.11.2 pytz-2017.2 $ pip freeze Django==1.11.2 pytz==2017.2
然后升级
virtualenvvwrapper
$ sudo pip3 install --upgrade virtualenvwrapper # ... Successfully installed pbr-3.0.1 six-1.10.0 stevedore-1.22.0 virtualenv-15.1.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.7.2
现在创建一个新的 virtualenv 工作:
$ mkvirtualenv -p `which python3.6` <VIRTUALENV_NAME>
pip
也有效:$ pip install django # ... Successfully installed django-1.11.2 pytz-2017.2 $ pip freeze Django==1.11.2 pytz==2017.2
Note: Now I realize it's a bit more than what you asked for, but (without knowing where exactly you failed) I guess you should be OK after step 2.
注意:现在我意识到这比你要求的要多一些,但是(不知道你到底失败在哪里)我想你在第 2 步之后应该没问题。
回答by Igonato
Had the same problem. Installing python from the source helped.
有同样的问题。从源代码安装 python 有帮助。
# Remove existing python 3.6 if installed with apt
$ sudo apt-get autoremove python3.6
# Get the source
$ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
$ tar xvf Python-3.6.1.tar.xz
$ cd Python-3.6.1
# Configure and install
$ sudo ./configure
$ sudo make altinstall
# Success!
$ pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
Edit:I since discovered pyenv. Makes installing and managing different python versions a lot easier. Give it a try!
编辑:我自从发现了pyenv。使安装和管理不同的 Python 版本变得更加容易。试一试!
回答by href_
I replaced Python 3.4 with 3.6 on my Ubuntu 14.04 servers and I had the same problem. In my case the cause seemed to be an ancient system pip:
我在我的 Ubuntu 14.04 服务器上用 3.6 替换了 Python 3.4,我遇到了同样的问题。就我而言,原因似乎是一个古老的系统 pip:
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
I have never installed python3-pip. Instead I solved the error as follows:
我从来没有安装过 python3-pip。相反,我按如下方式解决了错误:
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
回答by dirkaholic
I could not solve it by running
我无法通过运行解决它
python3 get-pip.py
or
或者
pip3 install --upgrade
because there I already had issues with pkg_resources.py. Also re-installing the python3-setuptools package from Ubuntu did not help as this still seems to install the one for the version originally installed with the Ubuntu system (3.4 in my case) but I could solve it by manually installing the setuptools via
因为在那里我已经遇到了 pkg_resources.py 的问题。同样从 Ubuntu 重新安装 python3-setuptools 包也没有帮助,因为这似乎仍然安装了最初随 Ubuntu 系统一起安装的版本(在我的情况下为 3.4),但我可以通过手动安装 setuptools 来解决它
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3
Note: python3 points to my new python version 3.6. If thats not the case for you then you would need to run
注意:python3 指向我的新 python 版本 3.6。如果您不是这种情况,那么您需要运行
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3.6
回答by gmccoy
I was having the same issue. It seems I had 2 versions of pkg_resources
on my system.
我遇到了同样的问题。pkg_resources
我的系统上似乎有 2 个版本。
/usr/local/lib/python3.6/site-packages/pkg_resources.py
/usr/local/lib/python3.6/site-packages/pkg_resources.py
/usr/lib/python3.6/site-packages/pkg_resources/__init__.py
/usr/lib/python3.6/site-packages/pkg_resources/__init__.py
Moving the old version so my system could find the newer version fixed it for me.
移动旧版本以便我的系统可以找到较新的版本为我修复它。
mv /usr/local/lib/python3.6/site-packages/pkg_resources.py /usr/local/lib/python3.6/site-packages/pkg_resources.py.back
mv /usr/local/lib/python3.6/site-packages/pkg_resources.py /usr/local/lib/python3.6/site-packages/pkg_resources.py.back
回答by Priyansh gupta
You can solve this error by using this command. it will update your setuptools
您可以使用此命令解决此错误。它将更新您的设置工具
python -m ensurepip --upgrade
回答by Christopher Hunter
I finally got around this by running:
我终于通过运行解决了这个问题:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.6 get-pip.py --force-reinstall
After this I can install python3.6 specific packages with:
在此之后,我可以安装 python3.6 特定的软件包:
python3.6 -m pip install <packagename>