I've installed python 3.9 on Xubuntu 20.04 using apt. When I try to run pip, I get the error, No module named 'distutils.cmd'
For example, python3.9 -m pip --help
gives the traceback
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/saul/.local/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/configuration.py", line 26, in <module>
from pip._internal.utils.logging import getLogger
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 27, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 39, in <module>
from pip._internal.locations import get_major_minor_version
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 14, in <module>
from . import _distutils, _sysconfig
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
Where can I find distutils.cmd
and where should I put it? I'm not at all knowledgeable about linux, just a naive user.
I found this post which indicated that there isn't a separate distutils module for python3.9, and seemed to suggest using virtual environments. When I tried
python3.9 -m venv /home/saul/.venvs/py39
however, I got the message
Error: Command '['/home/saul/.venvs/py39/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
CodePudding user response:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
(probably will give an error, I tried and it gave an error for me)
sudo apt install python3.9-distutils
python3.9 get-pip.py
(can skip and directly check the version, if it works then good otherwise run this command and then check version. I ran this command before checking version)
And finally,
python3.9 -m pip -V
(should give console as pip 22.x.x from some-path (python3.9)
)
I ran these commands, it worked for me. Hope it helps you too.
CodePudding user response:
I stumbled on this, which worked:
sudo apt install python3.9-venv