4

I am an Ubuntu noob and would like to ask you guys to help.

Currently I'm faced with 2 issues.

1st issue is when I'm trying mkvirtualenv --python=/usr/bin/python3.8 ENV, it threw me this error.

Error: RuntimeError: failed to query /usr/bin/python3.8 with code 1 err: 
'Traceback (most recent call last):\n  File 
"/home/yao1122/.local/lib/python2.7/site- 
packages/virtualenv/discovery/py_info.py", line 16, in <module>\n    from 
distutils.command.install import SCHEME_KEYS\nModuleNotFoundError: No module 
named \'distutils.command\'\n'

After googling from net, I decide to try install this. sudo apt-get install python3-distutils. Then it threw me this error.

Error: Unable to locate package python3-distutils

I am using ubuntu 16.04. Does anyone know what is the root cause?

Much appreciate your precious time for helping me out and THANK YOU in advance!

1
  • Try it with the original Python 3.5 that came with Ubuntu 16.04.
    – user535733
    May 13 '20 at 21:23
3

Ultimately I got it working on 16.04 using a solution I found in this thread.

Try to run the following in the terminal:

sudo apt-get install python-distutils-extra

Per the user who provided this answer, it would seem that python3-distutils ends up installed as a dependency of distutils-extra, though why this method works where other methods failed for me isn't clear.

0

python3-distutils and python3.8 are in the default Ubuntu 18.04 repositories, so you wouldn't get these errors in Ubuntu 18.04.


In Ubuntu 16.04 open the terminal and type:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.6
cd ~/Desktop/
wget -c http://launchpadlibrarian.net/449402985/python3-lib2to3_3.6.9-1~18.04_all.deb
wget -c http://launchpadlibrarian.net/449402975/python3-distutils_3.6.9-1~18.04_all.deb
sudo apt install ./python3-lib2to3_3.6.9-1~18.04_all.deb
sudo apt install ./python3-distutils_3.6.9-1~18.04_all.deb

You might need to run update-alternatives --config python3 after the first three commands to temporarily set python3.6 as the default Python 3.X version in order to install python3-lib2to3. Changing the default Python 3 version will break a lot of applications if you don't immediately change it back to the 16.04 system default Python 3 version after you finish installing python3-lib2to3 and python3-distutils and before you close the terminal. These two packages are also compatible with Python3.8, so after you finish installing them you won't need python3.6 and the ppa:deadsnakes/ppa anymore.

If you updated with a new python (from 3.5 to 3.6), then your /usr/bin/python3 points to the new python that does not have apt_pkg. Edit /usr/bin/add-apt-repository. Change the first line of /usr/bin/add-apt-repository from #! /usr/bin/python3.6 back to #! /usr/bin/python3

3
  • 2
    I have unmet dependencies. The following packages have unmet dependencies: python3-lib2to3 : Depends: python3 (>= 3.6.7-1~) but 3.5.1-3 is to be installed E: Unable to correct problems, you have held broken packages. my python3 version is 3.7.7
    – Byao
    May 14 '20 at 2:15
  • When i running this line sudo add-apt-repository ppa:deadsnakes/ppa , i got this error. ModuleNotFoundError: No module named 'apt_pkg' my python version now is 3.6.10
    – Byao
    May 14 '20 at 19:38
  • I edited my answer.
    – karel
    May 14 '20 at 23:31
0

I think there is an easier option:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.6 python3.6-dev python3.6-distutils

The deadsnakes packages provide many of the packages you might want for running python.

python3.*-venv
python3.*-2to3
python3.*-venv

https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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