Pip will not upgrade (wrong version of python?)

Previously, the installed version of python3 was 3.6. I needed the upgraded version (3.13), but I was not able to do that ‘normally’ (but I got some excellent help on this forum to get it installed). I aliased python3.13 to ‘python’.

HOWEVER, pip is now not working correctly. I was able to install (and use) ‘black’ using pip. BUT, when I tried to install a different package (the emoji package), it didn’t work (pip install emoji I even tried to specify a specific version, and tried using sudo).

What’s more of a concern is that I was unable to I even tried to update pip (using and I had the same (set of) error.

pip -V says the pip version is 21.3.1 and is linked to python3.6!!! (not 3.13.0) When I tried to update pip (pip install --upgrade pip), I got the same (set of) error as when I tried to install ‘emoji’ package. This is more of a concern, since it seems to be a problem with pip itself! I feel it is somehow related to pip being linked to an older (and default?) version of python.

How can I fix this? Do I need to link pip to 3.13.0 (or something like that)? It seems that 3.6 is the ‘default’, even though I have installed 3.13.0.

The complete error message is below:

> Defaulting to user installation because normal site-packages is not writeable
> ERROR: Exception:
> Traceback (most recent call last):
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
>     status = run_func(*args)
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
>     return func(self, options, args)
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 294, in run
>     wheel_cache = WheelCache(options.cache_dir, options.format_control)
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/cache.py", line 219, in __init__
>     self._ephem_cache = EphemWheelCache(format_control)
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/cache.py", line 193, in __init__
>     globally_managed=True,
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/utils/temp_dir.py", line 125, in __init__
>     path = self._create(kind)
>   File "/home/garth/.local/lib/python3.6/site-packages/pip/_internal/utils/temp_dir.py", line 164, in _create
>     path = os.path.realpath(tempfile.mkdtemp(prefix=f"pip-{kind}-"))
>   File "/usr/lib/python3.6/tempfile.py", line 499, in mkdtemp
>     prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
>   File "/usr/lib/python3.6/tempfile.py", line 269, in _sanitize_params
>     dir = gettempdir()
>   File "/usr/lib/python3.6/tempfile.py", line 437, in gettempdir
>     tempdir = _get_default_tempdir()
>   File "/usr/lib/python3.6/tempfile.py", line 372, in _get_default_tempdir
>     dirlist)
> FileNotFoundError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/home/garth']

Yikes. A completely different reason it doesn’t work. Same reason I couldn’t save a PNG file. Same reason I was unable to log in with a GUI (startx would give errors).

Stupid reason (which took me hours to figure out) – I was out of space!

HOWEVER, I still am wondering about pip since when I try to upgrade (pip install --upgrade pip), I get “Requirement already satisfied: pip in /home/garth/.local/lib/python3.6/site-packages (21.3.1)”. So, pip doesn’t apply to the newest installed version of python (3.13)? Note that python3.13 is installed in /usr/local/bin.

Bad idea. There are system scripts that depend on python being the version that ships with your OS.

Undo the python-alias and do not try to upgrade your OS’ python version. Always and only use alternative python versions inside venvs.

Sorry for the late reply, but I don’t know how to use a virtual environment (venv). I don’t know how to apply libraries, if they are temporary for that session (do I have to load them again each session), how pip is used in venv, …

Virtual environments are creates thus:

python -m venv <name_of_your_choice>

This command will create a directory called <name_of_your_choice> in your current working directory. This new directory is a virtual environment. The exact layout and contents of the venv depends on your operating system, consult the documentation.

Libraries are installed inside venvs with pip, same as you would normally. You just need to make sure you use the pip binary belonging to that particular venv. Do this by either

  1. Activating the venv (OS dependent, see documentation), and then simply call pip.
    or
  2. Calling pip by its full path.

Virtual environments are persistent.