Can't run pip on python 3.11

Viewed 1270

I'm on a fresh Ubuntu 20.4 install (or really, a reinstall, as I messed up some things and had to start over; everything except /home has been reformatted, so if there is an issue with remnants, it's there), with python 3.8 included. However, I want to run python 3.11, since that's the newest. I follow this guide, which basically amounts to

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update 
sudo apt install python3.11

coupled with

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1

I now, at least as far as I know, run version 3.11 as default. However, i run into problems with pip. Running just pip --version (or pip3 --version) returns

pip 21.3.1 from /home/usrname/.local/lib/python3.8/site-packages/pip (python 3.8)

In addition, when I run python -m pip (which now uses the 3.11 version) I get

/usr/bin/python: No module named pip

If I revert back to python3.8 -m pip, I get the welcome message with all the different commands pip has to offer. So that works fine.

(Because deadsnakes has version 3.11 marked as alpha at the moment, I also tried with 3.10. Same result there: no pip.)

I was under the impression that pip came bundled with python as default. How can I give my newer version of python a pip to play with?

3 Answers

I installed Python3.11 from the deadsnakes ppa, it doesn't come with ensurepip or pip, and the bootstrap script initially fails as it depends on distutils. I solved this by installing the optional distutils package and then bootstrapping.

apt install python3.11 python3.11-distutils
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

After downgrading to python 3.10 (because I didn't know 3.11 was still in development) and tinkering with a few commands, including

sudo apt install python3.10-pip

suddenly it works (I was completely certain I had tried that already). I also needed

sudo apt install python3.10-distutils

because pip said I had to. As well as, stolen from this answer,

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

to stop the

ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)

error message.

 sudo apt install python3.11-venv # as ensurepip is not installed at first
 python3.11 -m ensurepip
Related