6

After updating one of my Ubuntu 16.04 machines on AWS, python/pip appears to be broken.

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'

The system runs python3.6 installed through the jonathonf/python-3.6 ppa. Before the system update (apt-get update && apt-get upgrade) everything worked as expected. I also verified this on other machines I have not updated yet.

I have also had no luck installing python3.6 in a virtual environment on a fresh machine, so I guess a recent release or update broke something here?


edit:

I am also running into similar problems when installing on a fresh 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
7
  • It's strange that the call stack switched to a virtual env - what is the output of pip -V and your PATH? If the /home/ubuntu/virtualenvs/myenv/ dir is in the PATH, try removing it.
    – hoefling
    May 3, 2018 at 14:49
  • pip -v yields the same error as above. I am executing the commands from within the virtualenv, so removing its path from PATH defaults back to the system defaults (python3 outside venv, python2.7 pip).
    – Birne94
    May 3, 2018 at 14:54
  • oh, I see. Can you verify the file /usr/lib/python3.6/distutils/dist.py exists? If yes, then my guess is that you have another distutils module with same name in the sys.path that is found before the correct one, causing the error.
    – hoefling
    May 3, 2018 at 15:03
  • /usr/lib/python3.6/distutils/dist.py does not exist. The dist.py appears to be missing in both the global and the virtualenv site-packages.
    – Birne94
    May 3, 2018 at 15:26
  • Looks like your recent update borked the python3.6 installation, try reinstalling it. The dist.py shouldn't be available in a venv, this is correct. Instead, a venv provides a bootstrap script (path/to/venv/lib/python3.6/distutils/__init__.py) that imports all the necessary distutils stuff from the main installation.
    – hoefling
    May 3, 2018 at 15:38

6 Answers 6

5

I've tested the PPA in a fresh docker container and it looks like the package is broken, all distutils modules are missing after installation. Looks like the package was rebuilt recently; maybe this is a new issue.

You can open a bug and wait until the PPA maintainer fixes it, but aside from that, there's not much you can do. You can of course try fiddling the installation:

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

Of course, this is a very dirty stuff because I don't know what files should the correct package from that PPA have. Thus, I can give you no guarantee whatsoever whether this will work for you and not introduce any new bugs, but at least I could get pip running again and could install a package.

1
  • 1
    Thank you for confirming that I am not actually going crazy. I just switched to another ppa (deadsnakes/ppa) and everything appears to be working again.
    – Birne94
    May 3, 2018 at 16:54
3

This solves the problem for me on Ubuntu and Linux Mint. First confirm that python3.6 is installed through ppa:jonathonf/python-3.6 by running the commands:

ls /etc/apt/sources.list.d
sudo rm -i /etc/apt/sources.list.d/jonathonf-python-3_6-xenial.list

Then add the deadsnakes PPA using:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

And finally either remove/install or reinstall python3.6

sudo apt-get remove python3.6
sudo apt-get install python3.6

I also ran into unmet dependencies when reinstalling python. This was solved by manually removing libpython3.6-minimal. Hope this helps!

2

You're indeed not crazy, same problem here.

You can also try a previous version of the ppa from the same ppa, until they fix it: https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.6

example command line is:

apt-get install python3.6=3.6.3-1ubuntu1~17.04.york1
0

run

sudo apt update && sudo apt install -f && sudo apt upgrade

sudo apt-get install python3.6

to overcome broken installation

0

You can try this:

# dpkg -l | grep python3.5

You will get a list of dependencies, add them all to the end of this line:

# apt-get --purge remove <here>

Now run this:

# apt-get install python3.5-dev

Here is a link to a nice article: https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux

1
  • (3.5 is probably where you did damage, it is deeply woven into 16.04) Sep 8, 2018 at 10:19
0

I've just upgraded to disco dingo (19.04), and it broke my python3.6, with the following error message :

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

You can switch to Python 3.7 which seem to be the new default: tox -e py37 runs correctly.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.