pip disappeared after system upgrade

I upgraded from 22.10 to 23.04 just now without any problems. However, after the upgrade my pip is not working and I cannot figure out how to make it working again.

If i just want to call it:

pip
bash: /usr/local/bin/pip: cannot execute: required file not found

With sudo:

sudo pip
sudo: unable to execute /usr/local/bin/pip: No such file or directory

The executables are seemingly there:

ls -la /usr/local/bin/pip*
-rwxr-xr-x 1 root root 224 febr  21 12:13 /usr/local/bin/pip
-rwxr-xr-x 1 root root 224 febr  21 12:13 /usr/local/bin/pip3
-rwxr-xr-x 1 root root 224 febr  21 12:13 /usr/local/bin/pip3.10

If I call it within python (w conda):

python3 -m pip
/home/gerdos/miniconda3/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed

Without conda it seems to work, but acting strange:

python3 -m pip install --upgrade pip
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

I already tried to remove and install pip with apt, but it did not help.

sudo apt remove python-pip
sudo apt install python-pip

I use python 90% of the time I use my laptop, it would be essential for me to make pip and conda work properly. I have absolutely no idea what is going on.

So I found this answer: https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-manag

I understand the error: externally-managed-environment, however the rest of the question still stands. I guess my conda is broken?

Asked By: Gábor Erdős

||
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
sudo apt install python3-pip
Answered By: earthmeLon

First install pipx:

$ sudo apt install pipx

and then use it like this:

$ pipx install yt-dlp
$ pipx upgrade-all

Note that you should use pipx for installing Python packages under your "normal" user and not system-wide. Never use sudo pip ... or sudo pipx ...!

See also this AskUbuntu Question.

From https://pypa.github.io/pipx/:

pip is a general-purpose package installer for both libraries and apps with no environment isolation. pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

Answered By: FedKad

FWIW, on Ubuntu 20.04 I have been using

$ python3 -m pip --help
...

$ python3 -m pip install --upgrade pip
Collecting pip
  Downloading pip-23.2.1-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 1.2 MB/s 
Installing collected packages: pip
Successfully installed pip-23.2.1
$
Answered By: Hannu
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.