PyCharm virtualenv ModuleNotFoundError: No module named 'distutils.core'

Fresh installations of PyCharm on Linux Mint/Ubuntu raises error (during creation of new Project or virtual environment):

ModuleNotFoundError: No module named 'distutils.core'

The problem is that since Ubuntu 18.04 python modules required for work with virtual environments are not installed by default. Depending on the OS, how PyCharm is installed and Python version the solution might depend.

In order to fix the problem:

Traceback (most recent call last):
  File "/tmp/tmpmhuk7uzepycharm-management/setuptools-40.8.0/", line 11, in <module>
    import setuptools
  File "/tmp/tmpmhuk7uzepycharm-management/setuptools-40.8.0/setuptools/", line 6, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils.core'

You can use the most common solution which is (For Python 3):

sudo apt-get install python3-distutils

Step #1: Verify Python version and modules

First thing to do is verify the python installation, python version and some modules:

python -V
python3 -V

which can result in:

Python 2.7.17
Python 3.6.9

Now you can verify that you have: pip and setuptools for the targeted version, For example for Python 3:

by listing all python modules:

pip list


Package    Version
---------- -------
pip        20.0.2 
setuptools 40.8.0 

or per package:

$ pip3 show pip
Name: pip
Version: 9.0.1
Summary: The PyPA recommended tool for installing Python packages.
Author: The pip developers
Author-email: [email protected]
License: MIT
Location: /usr/lib/python3/dist-packages
$ pip3 show setuptools
Name: setuptools
Version: 45.2.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Author: Python Packaging Authority
Author-email: [email protected]
License: UNKNOWN
Location: /usr/local/lib/python3.6/dist-packages

If the packages are missing you need to install them by following next step.

Step #2: Install python3-distutils

The additional modules required for creation of new virtual environments can be installed by:

sudo apt-get install python3-distutils

expected output:

sudo apt-get install python3-distutils
[sudo] password for xnav:       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
The following NEW packages will be installed:
  python3-distutils python3-lib2to3
0 upgraded, 2 newly installed, 0 to remove and 65 not upgraded.
Need to get 222 kB of archives.
After this operation, 3143 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Unpacking python3-distutils (3.6.9-1~18.04) ...
Setting up python3-lib2to3 (3.6.9-1~18.04) ...
Setting up python3-distutils (3.6.9-1~18.0

or (if they are installed)

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-distutils is already the newest version (3.6.9-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 65 not upgrade

Once the installation is complete you need to restart PyCharm.

Step #3: Verify the modules in PyCharm

Once the installation is done and PyCharm is restarted you can verify the installation by checking PyCharm:

  • File
  • Settings
  • Project: ProjectName
  • Python Interpreter
  • Verify that exists
    • pip
    • setuptools
  • Upgrade if needed - from the triangle


Share Tweet Send
You've successfully subscribed to SoftHints - Python, Data Science and Linux Tutorials
Great! Next, complete checkout for full access to SoftHints - Python, Data Science and Linux Tutorials
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.