platformio / platformio-vscode-ide

PlatformIO IDE for VSCode: The next generation integrated development environment for IoT

Home Page:https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ModuleNotFoundError: No module named 'distutils.***'

Zukatomo opened this issue · comments

Solution

Some Linux distributives have a limited Python3 installed by default. Please open your system terminal and type:

sudo apt-get install python3-distutils

Now, restart VSCode. If it does not work, try to install sudo apt-get install python3-venv. Restart VSCode.


%23 Description of problem
Leave a comment...

BEFORE SUBMITTING, PLEASE SEARCH FOR DUPLICATES IN

%23 Configuration

VSCode: 1.36.1
PIO IDE: v1.8.0
System: Linux, 5.0.0-20-generic, x64

%23 Exception

Error: Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv 
 Error: Virtualenv Create: Traceback (most recent call last):
  File "/home/xi/.platformio/.cache/tmp-11633a521cEj3iqkN/virtualenv-16.1.0/src/virtualenv.py", line 20, in <module>
    import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'


	at t.value (/home/xi/.vscode/extensions/platformio.platformio-ide-1.8.0/node_modules/platformio-node-helpers/dist/index.js:1:28858)

Yup, that looks to be the culprit. I'd suggest the shortcut of installing python3-venv over python3-distutils (and then probably python3-venv anyway), since it seems python3-distutils is a dependency of python3-venv. Having said that, installing python3-distutils was enough to allow the platformio install to continue in the below VM, so debatable? Which will win... simplicity or the minimalist approach? Dang it... sudo apt install -y python3-distutils python3-venv will fix it for certain! 😆

On a reasonably untouched Ubuntu 18.04 VM (although it hadn't been booted in a couple of months), which didn't have vscode or platformio on it yet, neither python3-distutils nor python3-venv were present, running a simulated apt install for python3-venv resulted in (last lines being the most important):

pfeerick@Ubuntu-VirtualBox:~/Downloads$ sudo apt install -s python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython3-stdlib libpython3.6 libpython3.6-minimal libpython3.6-stdlib
  libssl1.1 python-pip-whl python3 python3-distutils python3-lib2to3
  python3-minimal python3.6 python3.6-minimal python3.6-venv
Suggested packages:
  python3-doc python3-tk python3.6-doc binfmt-support
The following NEW packages will be installed:
  python-pip-whl python3-distutils python3-lib2to3 python3-venv python3.6-venv

vs

pfeerick@Ubuntu-VirtualBox:~/Downloads$ sudo apt install -s python3-distutils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython3-stdlib libpython3.6 libpython3.6-minimal libpython3.6-stdlib
  libssl1.1 python3 python3-lib2to3 python3-minimal python3.6
  python3.6-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.6-venv python3.6-doc
  binfmt-support
The following NEW packages will be installed:
  python3-distutils python3-lib2to3

If python3-venv is not installed, we will use own to make a virtual environment. The problem is in distutils. This is a built-in package in Python. I don't know how ubuntu maintainers removed it from Python. What is more, I don't know what was the reason for it. As a result, default Ubuntu's Python3 is not NORMAL/Official Python3 from python.org. It looks very close to Python which we have on network routers. But.. here is a reason - flash space! Strange guys.

Nice... so only distutils should be needed then. I can't see why python3-distutils isn't installed... it seems to stem from the debian repo though - as there is a mention of "With python 3.6, python3-distutils is no longer installed by default." in a bug report... but... um... why? Whilst distutils is being phased out... it hasn't been dropped yet! 🤦‍♂️ 🤕

I am seeing this error or one very similar on a newly setup ubuntu 19.10 system when I try to install platform-ide into Atom.

Error: Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv
Error: Virtualenv Create: Traceback (most recent call last): File "/home/colinl/.platformio/.cache/tmp-13725OU6yqYA4yTcO/virtualenv-16.7.5/virtualenv.py", line 24, in import distutils.spawn ModuleNotFoundError: No module named 'distutils.spawn'
at t.value (/home/colinl/.atom/packages/platformio-ide/node_modules/platformio-node-helpers/dist/index.js:1:32251)

However I am using Python 2.7
$ python --version
Python 2.7.17rc1
There does not appear to be a python-distutils package so I am at a loss what to do.

OK, I see the problem. Even though python --version shows 2.7 python 3 is apparently also installed and platformio is using that. The workaround above to install python3-distutils fixes it.

I also had 2.7 installed alongside 3. The 'Dang it' (sic) approach fixed it. Definitely an issue.