Pip is not working for Python 3.10 on Ubuntu

31,264

Solution 1

This is likely caused by a too old system pip version.

Install the latest with:
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10

Solution 2

I have tried all the answers above but nothing worked for me. My python3 version is 3.10.2.

So I need to install the appropriate version for pip.

However, I have tried

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10

But didn't work so, I tried

curl https://bootstrap.pypa.io/get-pip.py | Sudo python3

This worked for me

Solution 3

I've had this problem inside GitHub Actions. My solution was to resort to virtual environments to isolate from the rest of the system. Ensure python3.10-venv is installed and then do

python3.10 -m venv .venv
source .venv/bin/activate
pip install ...
...
deactivate

Solution 4

This is an expanded version of @mirekphd's comment which gave me a solution that worked both on my laptop and on our server perfectly without messing anything up.

First step, if not already done is to add the 'deadsnakes' repository so that the latest python related software can be downloaded and kept updated.

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa

And, if you don't have Python 3.10 already installed you can do that with:

sudo apt install python3.10

And finally, to make pip work you will need to install the distutils package that's compatible with 3.10:

apt install python3.10-distutils

After that you can use pip the following way:

python3.10 -m pip _rest_of_the_pip

The above is necessary because the regular pip command will utilize the systems default python version and not 3.10.

If you use pip frequently then you can add an alias to your .bashrc file such as:

alias pip310='python3.10 -m pip'

After that you can just use it like this:

pip310 install blah

Solution 5

Try:

pip3.10 install <package name>

Make sure you have the latest version pip and python3.10

Share:
31,264

Related videos on Youtube

Christopher Coco
Author by

Christopher Coco

Updated on February 26, 2022

Comments

  • Christopher Coco
    Christopher Coco over 2 years

    I am new to using Ubuntu and Linux in general. I just attempted to update Python by using sudo apt-get install python3.10. When I run python3.10 -m pip install <library name> I always receive the following error:

    Traceback (most recent call last):
      File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
        sys.exit(_main())
      File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
        command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
        module = importlib.import_module(module_path)
      File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
        from pip._internal.cli.req_command import RequirementCommand
      File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
        from pip._internal.index.package_finder import PackageFinder
      File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
        from pip._internal.index.collector import parse_links
      File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
        from pip._vendor import html5lib, requests
    ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)```
    

    I have tried doing sudo apt-get install python3.10-html5lib it downloaded something but it did not fix the error. How should I fix this error?

    • Timo
      Timo over 2 years
      It is important to grasp that when installing python, pip will not come automatic with it. You have to install the module separately, as seen in the answer by nnn
  • nnn
    nnn over 2 years
    OP already installed python3.10, perhaps after adding a third party repo like sudo add-apt-repository ppa:deadsnakes/ppa && sudo apt update
  • Timo
    Timo over 2 years
    ... and do not follow the first google search result for installation of pip - apt install python3-pip, it installs python3.8 together with pip on Ubuntu 20.04 as of today.
  • Timo
    Timo over 2 years
    On Ubuntu 20.04 with python3.10 from deadsnakes-ubuntu-ppa-focal.list installed, I get ModuleNotFoundError: No module named 'distutils.cmd'
  • mirekphd
    mirekphd over 2 years
    You can apt install python${PYTHON_VERSION}-distutils from deadsnakes repo, but tell me please when you succeed installing numpy with pip3.10.
  • Timo
    Timo over 2 years
    @mirekphd thanks for the hint, I will try numpy - a side info: consider to address your comment to me with the "at sign plus user" so that I can be aware of it.
  • mirekphd
    mirekphd over 2 years
    Apparently ensurepip is not available in Ubuntu/Debian (/usr/bin/python3.10: No module named ensurepip)
  • QuentiumYT
    QuentiumYT over 2 years
    Well no clue :/ I had just ensurepip with my python3.10 (DL from deadsnake ppa) and it fixed my pip installation
  • EdisonMaxwell
    EdisonMaxwell over 2 years
    The latest pip version is 21.3.1 though. Have you tried the above command?
  • ScipioAfricanus
    ScipioAfricanus over 2 years
    AttributeError: module 'collections' has no attribute 'MutableMapping' Errors out.
  • alvaro nortes
    alvaro nortes over 2 years
    These two commands worked for me on Ubuntu18: curl -sS bootstrap.pypa.io/get-pip.py | python3.10 && apt-get install -y --no-install-recommends python3-pip
  • devp
    devp over 2 years
    For those who are wondering how this command works: curl is used to download the file from the given link the parameter -sS means s (small s) represent silent and S (capital s) means show error. Curl will download the get-pip.py file which has some python code and then we pass the code to python3.10 command this way python3.10 will run get-pip.py and this way latest version of pip will be installed
  • Flaiming
    Flaiming over 2 years
    This worked for me, thanks!
  • adem.sh
    adem.sh about 2 years
    This sould be the right answer.
  • mingchau
    mingchau almost 2 years
    thanks, really saved my day! Important to issue with the sudo
  • Tushar
    Tushar almost 2 years
    You should small case sudo so that it doesn't fail on copy and paste.