18

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?

Arthur
  • 653
  • 2
  • 6
  • 21
  • Try to use pip3. For example, pip3 install numpy – Danila Musaev Dec 07 '21 at 13:02
  • @DanilaMusaev `pip3 --version` still gives the same `pip 21.3.1 from /home/usrname/.local/lib/python3.8/site-packages/pip (python 3.8)` message. `pip3 install numpy` tells me numpy is already installed. `python3.8 -m numpy` complains that numpy isn't executable. `python -m numpy` (with v3.11), on the other hand, tells me I don't have numpy installed. – Arthur Dec 07 '21 at 13:06
  • Python 3.11 is currently in the early alpha stage of the development. Unless you are taking part in the development process, you should use Python 3.10 as the latest stable release. Really. – VPfB Dec 07 '21 at 13:12
  • @VPfB Sure. I tried that. I still have the same problem, though: it doesn't have pip. – Arthur Dec 07 '21 at 13:37
  • @Arthur try to reinstall the pip: https://docs.python.org/3/library/ensurepip.html and use the `--user` option – VPfB Dec 07 '21 at 13:44
  • @VPfB `/usr/bin/python: No module named ensurepip` is what that gives me. Both with 3.8, 3.10 and 3.11. And trying to install it with `pip install ensurepip` gives `Defaulting to user installation because normal site-packages is not writeable ERROR: Could not find a version that satisfies the requirement ensurepip (from versions: none) ERROR: No matching distribution found for ensurepip` – Arthur Dec 07 '21 at 13:50
  • `ensurepip` is a part of the Python installation. If not found, either `/usr/bin/python` is not Python 3.4+, or your installation is corrupted and you have to fix it. In an environment with multiple Python versions like yours, use explicit `/usr/bin/python3.10` – VPfB Dec 07 '21 at 14:04
  • @VPfB I thought the same about pip. But apparently that's not the case for my installation. `/usr/bin/python` is now 3.10 (I removed 3.11 because, as you said, alpha). But that hasn't solved any of my problems. Is it the deadsnakes repository's fault? Or have I just gotten a bad download? Maybe. – Arthur Dec 07 '21 at 14:06
  • Strange. Last check: Does `/usr/bin/python -V` display '3.10.0' ? Does `/usr/bin/python -c 'import ensurepip3'` print any errors? – VPfB Dec 07 '21 at 14:12
  • @VPfB Yes to both. The error is `ModuleNotFoundError: No module named 'ensurepip3'`. – Arthur Dec 07 '21 at 14:14
  • @VPfB I tried that too. Same result (only without the `3`) – Arthur Dec 07 '21 at 14:17
  • I'm afraid I have no more ideas how to help remotely. The import should be successful. I think your Python 3.10 installation is somehow broken. You should have a `/usr/lib64/python3.10/` directory and there should exist an `ensurepip` subdirectory. – VPfB Dec 07 '21 at 14:22
  • @VPfB I could try to remove the installation and try again. But there is at the moment no python-related directory in `lib64`. – Arthur Dec 07 '21 at 14:27

4 Answers4

32

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
mfurseman
  • 748
  • 8
  • 11
  • 1
    does not work. `pip --version` still shows old version of python. what to do ? – D.L Feb 08 '23 at 17:41
  • 2
    @D.L you probably have multiple versions of Python on your path, try being explicit with `python3.11 -m pip --version` and see if you get the expected result. – mfurseman Feb 08 '23 at 20:50
  • i confirm that this explicit method does work. Although, rather annoying that the user has to specify the python version each time they want to use pip. Surely pip without a version in front should default (or be aliased) to the latest version... which seems to be the case with windows. – D.L Feb 09 '23 at 11:28
  • 1
    @D.L This is a property of your environment, not something intrinsic to Python. You can configure it yourself, use your package manager to set defaults for your entire system, or use `pyenv` for a high level of configurability. – mfurseman Feb 13 '23 at 12:00
  • that works thanks, I also added aliases for python and pip to make it easier: alias python="python3.11" alias pip="python3.11 -m pip" – kareemhossam Jun 04 '23 at 12:09
17
 sudo apt install python3.11-venv # as ensurepip is not installed at first
 python3.11 -m ensurepip
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
2

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.

Arthur
  • 653
  • 2
  • 6
  • 21
-2

i didnt bother trying to install pip separately. since i've successfully installed python3.11, simply do this to install dependencies

python -m pip install --upgrade pip \
    && python -m pip install -r requirements.txt
mike01010
  • 5,226
  • 6
  • 44
  • 77