I was using Debian 11 and had installed python3.9 in addition to the Debian 11 system version of python 3.9.
I installed jupyter notebooks on my version of python3.9 (not the debian included version) and was able to use jupyter lab
to run jupyter labs. From here I selected my venv kernel depending on the project I was working on to work within a venv.
Now I have updated to Debian 12 which has a system version of python 3.11. But I'm having issues finding my existing installation of python 3.9 and all my installed packages such as jupyter. For exmaple, if I run:
jupyter lab
I get this:
Traceback (most recent call last):
File "/home/gary/.local/bin/jupyter-lab", line 5, in <module>
from jupyterlab.labapp import main
ModuleNotFoundError: No module named 'jupyterlab'
Here are the outputs for various console commands:
which pip /home/<my_username>/.local/bin/pip
which pip3 /home/<my_username>/.local/bin/pip3
which pip3.9 /home/<my_username>/.local/bin/pip3.9
which pip3.11 /usr/bin/pip3.11
which python
which python3 /usr/local/bin/python3
which python3.9 /usr/local/bin/python3.9
which python3.11 /usr/bin/python3.11
printenv
includes:
PATH=
/home/<my_username>/.local/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/local/games:
/usr/games:
/snap/bin
In the /home/<my_username>/.local/bin/
directory I can see all the jupyter files installed. If I run python3.9
to open a python shell within a terminal, I am able to import jupyter successfully.
However when I run pip3.9 list
jupyter is note in there. If I try to run pip3.9 install jupyter-lab
it gives me this error:
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.
It's referencing 3.11, indicating it's trying to run this command with the debian system python installation, even though I explicitly called python3.9
. How do I fix this without breaking the system installation?
I followed the instructions as outlined in the link provided by stefan_aus_hannover: https://linuxconfig.org/how-to-change-default-python-version-on-debian-9-stretch-linux
I did this for both python
and python3
and it seems to work now.