9
Python 3.7.2
Pip 18.1
setuptools 40.7.2
Windows-10-10.0.14393-SP0

I've seen people having the No module named 'distutils issue on Linux/Ubuntu (for example, here and here). The reported solution is installing distutils with apt-get:

apt-get install python3-distutils

Or, people had the issue very long ago (for example, here).

However, I'm getting this error on new Windows (Windows-10-10.0.14393-SP0), new Python (3.7.2) and cannot figure out why distutils is upset and/or how to install distutils.

I can import distutils in Python so I assume it to be installed. But setuptools is unhappy.

File "site-packages\setuptools\__init__.py", line 6, in <module>
ModuleNotFoundError: No module named 'distutils'

Directly from Python, it doesn't complain about distutils.

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils.core
>>> import setuptools
>>>

But, when I try to run a Python script, it complains. Any thoughts?

DarkerIvy
  • 1,477
  • 14
  • 26
  • What is the exception context? E.g. do you run any specific command, are you in a virtual environment etc. What are the steps to reproduce the error? – hoefling Feb 02 '19 at 11:50
  • maybe this is a linux rookie hint: But if you get asked whether you're root... try sudo apt-get install python3-distutils. – mrk Jul 11 '19 at 20:23

2 Answers2

3

This error might show up in case if you created a new virtual environment while creating the project.

You can sort it out by opening the directory where your project is present, and then by searching and deleting the "venv" folder.

Now when you will re-run the project, the IDE is gonna ask you to setup the python interpreter. At that time instead of selecting the virtual environment, go with the option for using pre-existing interpreter option.

-- What happens when you select "create virtual environment" is that your IDE creates a new directory named "virenv" and copies all the python files from Python/bin to this folder and then import modules from here. So the module might be already installed in the native python directory but might no be imported to the virenv directory and hence resulting in the ModuleNotFoundError.

Jente Rosseel
  • 1,195
  • 1
  • 10
  • 18
  • Nothing wrong answer as such, but it would help if you structured it in paragraphs for easier reading. – Harijs Deksnis Jun 08 '19 at 07:25
  • Even though it's not exactly right, this answer helped me figure out the issue so I accepted it. In a virtual env, distutils is not an actual package but a skeleton pointing to the non-virtual Python install distutils. I'm not sure how many packages get this treatment. To get a "real" distutils, you have to go outside the virtual env. – DarkerIvy Aug 28 '19 at 19:19
2

Ok, I know, my solution may be the worst, but it worked for me, just copy the distutils folder in my virtual environment in the same location to distutils, and the problem was solved

xanonimoxp
  • 29
  • 3