Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkvirtualenv says "no module named distutils.spawn" when making a venv for non-default python on Raspbian Buster

Raspbian Buster has Python3.7 by default. I'm trying to make a Python3.6 virtualenv. I have a fresh install of Raspbian Buster with Desktop (not the version that is with "recommended software") and have already sudo apt-get update; sudo apt-get upgrade'd.

  1. I have run sudo apt-get install python3.6-dev to get Python 3.6.
  2. I then run pip3 install virtualenvwrapper and added the appropriate lines to my .bashrc.
  3. When I run mkvirtualenv --python=/usr/bin/python3.6 venv it gives the following error
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/virtualenv.py", line 24, in <module>
    import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'

I have searched for answers already and nothing has helped. Here's what I've done (as far as I can remember).

  • I tried adding export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6 to my .bashrc and it didn't help.
  • I tried python3.6 -m pip install virtualenvwrapper and get another distutils error:
    Traceback (most recent call last):
    File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
    File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
    from pip._internal import main as _main  # isort:skip # noqa
    File "/usr/lib/python3/dist-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
    File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
    File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
    File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module>
    from pip._internal.locations import USER_CACHE_DIR, src_prefix
    File "/usr/lib/python3/dist-packages/pip/_internal/locations.py", line 10, in <module>
    from distutils import sysconfig as distutils_sysconfig
    ImportError: cannot import name 'sysconfig'
    
  • I can successfully do mkvirtualenv venv but of course that uses Python 3.7 which I don't want.
  • I tried sudo apt-get install python3-distutils --reinstall but it only seems to install the Python3.7 version. There is no python3.6-distutils package.

Anyone know anything about how to get this working?

like image 604
user1505021 Avatar asked Oct 09 '19 18:10

user1505021


2 Answers

I had the same problem using python3.8 and virtualenv. I found that I did not install venv of the corresponding version of python. Then I install it with

sudo apt install python3.x-venv

The problem is solved. Have a try and good luck!

like image 181
Yuxin Zhao Avatar answered Oct 07 '22 02:10

Yuxin Zhao


I had the same issue (ModuleNotFoundError: No module named 'distutils.spawn'). The problem was that PIP for python3 was not preinstalled on my system. The venv was created without problem after installing it manualy:

sudo apt install python3-pip
like image 31
dannymo Avatar answered Oct 07 '22 00:10

dannymo