Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'distutils.core'

I've recently upgraded from Ubuntu 18.04 to 19.04 which has python 3.7. But I work on many projects using Python 3.6.

Now when I try to create a virtualenv with Python 36 in PyCharm, it raises:

ModuleNotFoundError: No module named 'distutils.core' 

enter image description here

I can't figure out what to do.

I tried to install distutils:

milano@milano-PC:~$ sudo apt-get install python3-distutils Reading package lists... Done Building dependency tree        Reading state information... Done python3-distutils is already the newest version (3.7.3-1ubuntu1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

But as you can see I have the newest version.

Do you know what to do?

like image 678
Milano Avatar asked Apr 18 '19 15:04

Milano


People also ask

How to fix modulenotfounderror-no module named distutils in Python?

Latest Python and ModuleNotFoundError: No module named 'distutils.util' Module distutils is not included in the latest versions of Linux Mint 20 (Ubuntu 20) which cause errors in pip and PyCharm. To solve this error we need to install distutils package - for the latest version of Python 3 which is included in the OS:

Why is the distutils module not found in this upgrade?

The module not found likely means the packages aren't installed. If they're already installed you can try to fix anything that may have been messed up in the upgrade with... Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes.

Why is the module not found in Ubuntu 20?

The module not found likely means the packages aren't installed. If they're already installed you can try to fix anything that may have been messed up in the upgrade with... Show activity on this post. I got this problem after upgrading to Ubuntu 20.04.

Why can't I install distutils on Debian?

you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.


1 Answers

Python base interpreter does require some additional modules. Those are not installed with e.g. Ubuntu 18.04 as default.

To solve this we need to first find the python version you're running. If you have only installed one python version on your system (and you are sure about it) you can skip this step.

# from your project interpreter run # your_project_python --version $ python3 --version Python 3.7.8 

You now need to install for this precise python interpreter the distutils. So here the solution for this example would be:

sudo apt install python3.7-distutils # sudo apt install python3-distutils  # would just update default python intrpreter 

Keep in mind, that just running python from any command line might be an other version of python then you're running in your project!

If this hasn't helped, look for the following possibilities. This will bring you the binary which resolved from the alias in the command line.

$ which python /usr/bin/python $ ls -lach /usr/bin/python lrwxrwxrwx 1 root root 9 Jun  8  2018 /usr/bin/python -> python2.7 

original source: refer to this article

For this answer I've also merged, summarized, ordered and explained some of the content which has been provided by Neo, Andrei, Mostafa and Wolfgang.

As a side note for sorcerer's apprentice: You might be tempted to uninstall python interpreters. For proposed solution not necessary at all!! How ever, keep in mind that there is one python interpreter which your whole OS depends on. So this default one, you don't want to uninstall. If you do so, you're in a certain mess in finding your desktop taskbar and basically everything.

like image 123
Cutton Eye Avatar answered Oct 14 '22 16:10

Cutton Eye