本文介绍了在 ubuntu 上将 python3.4 升级到 python3.6 会破坏 pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前拥有 python3.4 之后,我正尝试在我的机器上安装 python3.6.但是,安装后尝试在 python3.6 下运行 pip 给了我错误:

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:

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?

推荐答案

我设法解决了它,而无需从源代码安装任何东西.这是我所做的:

I managed to solve it without installing anything from sources.Here's what I did:

  1. 首先,为 Python3.x 安装 pip(因为一些奇怪的原因我没有它......)

  1. First, install pip for Python3.x (for some weird reason I didn't have it...)

$ 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)
    

    1. 然后升级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 工作:

  • Now creating a new virtualenv works:

    $ 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
    

  • 注意:现在我意识到这比你要求的要多一些,但是(不知道你到底失败在哪里)我想你在第 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.

    这篇关于在 ubuntu 上将 python3.4 升级到 python3.6 会破坏 pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    07-31 18:45