Updating python3.4 to python3.6 on ubuntu breaks pip

I am trying to install python3.6 on my machine after I currently have python3.4. However, after installation trying to run pip under python3.6, an error occurs:

 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 this error, but none of them contain any actual suggestions for permission. Does anyone know how I can fix this?

+27
source share
7 answers

I managed to solve this without installing anything from the sources. Here is what I did:

  • First install pip for Python3.x (for some strange reason I didn't have one) ...

     $ sudo apt-get install python3-pip 

    This is an old version ...

     $ pip3 --version pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4) 
  • ... so update it to the last

     $ sudo pip3 install --upgrade pip 

    Now it's much better

     $ sudo pip3 --version pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4) 

  1. Then update 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 
  2. Now create a new virtualenv file:

     $ 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 

Note. Now I understand this a little more than what you asked, but (not knowing exactly where you failed), I think you should be fine after step 2.

+20
source

Had the same problem. Installing python from the source helped.

 # 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 have since discovered pyenv . Makes installing and managing various versions of python much easier. Give it a try!

+13
source

I replaced Python 3.4 with 3.6 on my Ubuntu 14.04 servers and I had the same problem. In my case, the reason seemed to be an ancient system:

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

 $ sudo pip install --upgrade pip $ sudo pip install --upgrade virtualenv 
+2
source

I had the same problem. It seems I had two versions of pkg_resources on my system.

/usr/local/lib/python3.6/site-packages/pkg_resources.py

/usr/lib/python3.6/site-packages/pkg_resources/__init__.py

Moving the old version so that my system can find a 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

+1
source

I could not solve this by running

 python3 get-pip.py 

or

 pip3 install --upgrade 

because i already had problems with pkg_resources.py. Also, reinstalling the python3-setuptools package from Ubuntu did not help, as it still seems to be installed for the version originally installed with the Ubuntu system (in my case 3.4 in my case), but I could solve it manually installing setuptools through

 wget https://bootstrap.pypa.io/ez_setup.py -O - | python3 

Note: python3 points to my new version of python 3.6. If it is not, then you will need to run

 wget https://bootstrap.pypa.io/ez_setup.py -O - | python3.6 
0
source

You can solve this error using this command. it will update your setuptools

 python -m ensurepip --upgrade 
0
source

Just download the get-pip.py file here and use this command:

 sudo python3 get-pip.py 
-2
source

Source: https://habr.com/ru/post/1269228/


All Articles