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

3

11

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?

Schroder answered 9/10, 2019 at 18:53 Comment(0)
L
19

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!

Lifework answered 7/4, 2020 at 2:33 Comment(0)
R
4

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
Rattail answered 17/2, 2020 at 22:14 Comment(0)
A
0

I had similar error when running the command virtualenv venv --python=python3.x Below is what worked for me.

Desktop/yourproject$python --version

Desktop/yourproject$python3.x -m venv yourvenv
Astrogation answered 5/12, 2020 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.