skip to Main Content

I want to upgrade the version of python, numpy, matplotlib, and scipy that I am using on a Ubuntu 22.04 desktop, to mirror the versions that I have on my laptop.

Running apt list --installed reveals that the following packages (amongst many other python ones) were installed via apt-get when the desktop was set up for me:

python3-matplotlib-inline/jammy,jammy,now 0.1.3-1 all [installed]
python3-matplotlib/jammy,now 3.5.1-2build1 amd64 [installed]
python3-numpy/jammy-updates,jammy-security,now 1:1.21.5-1ubuntu22.04.1 amd64 [installed,automatic]
python3-scipy/jammy,now 1.8.0-1exp2ubuntu1 amd64 [installed,automatic]
python3.10-dev/jammy-updates,jammy-security,now 3.10.12-1~22.04.3 amd64 [installed,automatic]
python3.10-minimal/jammy-updates,jammy-security,now 3.10.12-1~22.04.3 amd64 [installed,automatic]

so in particular the last two show that I am running python 3.10.12.

In order to upgrade to python 3.11 I ran

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

This gave me bare python, but I’m now having trouble upgrading my libraries, which I would like to manage through pip. In particular I get

$ pip install numpy --upgrade
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in ./.local/lib/python3.10/site-packages (1.26.4)

and similar when I try to upgrade matplotlib – because those packages are already installed, pip doesn’t want to touch them.

Is there a way I can install the new packages on my system and "point" my installation of python 3.11 at them? Ideally I would like to have it system wide and not use virtual environments (mainly because I don’t understand them, and I just want to be able to call my scripts from anywhere).

As a bare minimum I would like to know how to upgrade to matplotlib 3.8.2 and import it when running a python 3.10 kernel instead of the current mpl 3.5.1, but ideally upgrade everything.

2

Answers


  1. Check which python you use, probably bundled with system one. Create virtual environment for with installed python 3.11 (python -m venv directory_name), activate it and use pip from venv. From my experience this is the easiest way to use desired python version on ubuntu.

    Login or Signup to reply.
  2. A better way to do this is using virtual environments which you can create to follow the specific conditions and dependencies you want
    You can create multiple environments, with different python versions and packages with specified versions
    There’re many ways to do that, I especially like
    Miniforge, its a great free solution for python version and environment management
    It supports linux, windows and OSX.
    Simple to install and use.
    Installation instructions from the readme:

    curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
    bash Miniforge3-$(uname)-$(uname -m).sh
    

    Example, create an environment called "myenv" with python 3.11 and numpy, matplotlib and scipy:

    conda create -n myenv python=3.11 numpy matplotlib scipy
    

    To use the environment use:

    conda activate myenv
    python main.py
    

    It’s also supported by IDEs like Visual Studio Code which is also available on Ubuntu

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search