Score:0

Failing to create a virtualenv using python3.7 in Ubuntu 20.04

cn flag

I have a system running Ubuntu 20.04.5 LTS which comes with python3.8 by default. For some work purposes, I need to use a virtual environment in python 3.7. So, I installed python3.7 which has been successfully installed.

The output for $ python3.7 --version results in Python 3.7.15 as output and $ python3.7 results in python3.7 shell.

So, now I installed pip using, (as per documentations)

$ sudo apt install python3-venv python3-pip

$ python3 -m pip install --upgrade pip setuptools wheel

For installing virtualenv I went via,

$ python3.7 -m pip install virtualenv

which went without a hitch.

Now to create my virtual environment, I went through, $ python3.7 -m virtualenv /path/to/venv/

which fails by giving me a ModuleNotFoundError: No module named 'distutils.util' error,

The entire output being,

$ python3.7 -m virtualenv /path/to/venv/
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "_main_", mod_spec)
  File "/usr/lib/python3.7/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.cli.main import main as _main  # isort:skip # noqa
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, 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 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'

How do I go forth resolving this? all I want is a python3.7 virtual environment in a Ubuntu 20.04 system.

Score:0
cn flag

I resolved the issue by installing distutils for python3.7 by $ sudo apt install python3.7-distutils

This fixed the issue and i was able to create the virtualenv successfully.

Only thing i had to keep in mind was to use pip3.7 in the virtual environment since the pip installed initially was based on python 3.8.10

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.