I have installed python3.9 through apt in my Ubuntu 18.04.6 LTS. Then I was trying to create a new virtual environment that runs on 3.9. This is the process I did:
$ python3.9 -m venv /home/user1/py3.9
Error: Command '['/home/user1/py3.9/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
To remedy this I tried upgrading pip, which raised an error regarding distutils. Here was the output of that:
$ python3.9 -m pip install --upgrade pip
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)
I then installed distutils using the command: sudo apt install python3.9-distutils
, which was sucessful and after that I could upgrade pip.
But I'm still having the same problem of returned non-zero exit status 1
if I try to create the virtual environment. I'm not sure what I did wrong. But I did install python3.11 in the past and could create virtual environment the same way IIRC. I'm not sure what to do at this point.