2

python3 is a system wide program, just as pip3 is.

I want to install IPython on Debian 12 (Bookworm). (This information is also relevant to newer Ubuntu versions, since these are derived directly from Debian and contain the same policy change.)

I would probably expect this to also be a system-wide available program, just like python3 and pip3. Please correct me if that no longer makes sense, given the recent changes which prevent (by default) users from installing pip3 packages system wide, instead encouraging the use of venvs.

Previously I would have run pip3 install ipython. What should I now do instead?

Error message when attempting to run pip3 install ipython.

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. 
3
  • Use virtual environment, or pipx. Commented Sep 8, 2023 at 22:32
  • See also this answer regarding pip and /usr/lib. Commented Oct 1, 2024 at 20:46
  • The arguably correct way to install ipython is through apt (sudo apt install python3-ipython, just like you probably at one time did with python3 and python3-pip). All answers seems to focus on how to use pip, rather than answering how to install ipython. Commented Jul 7 at 15:35

4 Answers 4

2

The actual solution I used, thanks to others for directing me to venv.

python3 -m venv .venv source .venv/bin/activate # do this every time to use the venv created above pip3 install ipython 

FYI for convenience one can also do

ln -s .venv/bin/activate . . activate 
Sign up to request clarification or add additional context in comments.

Comments

2

Answers are ridiculous. If you can type python from anywhere in the system, you should be able to type ipython. Nothing wrong with virtual environments but they are for projects.

The solution:

pip install --user ipython --break-system-packages 

And no, you won't break system packages.

If you get the warning WARNING: The scripts ipython and ipython3 are installed in '/home/<user>/.local/bin' which is not on PATH. add it to your PATH:

echo "PATH=$PATH:~/.local/bin" >> ~/.bashrc 

3 Comments

I suppose it depends if you want ipython to be available system wide by default. Since it's not a core part of the Linux system my personal preference is to avoid making it a core part of the Linux system. But it seems unlikely that one or the other choice will result in any particually negative consequences. That said - if you want to use pyenv to manage python versions, it is probably a good idea not to make ipython a core part of your OS. Otherwise managing ipython versions is probably going to become a bit complicated
Why would you want to use something with the scary name "break-system-packages "? At least it ought to be explained why it won't break system packages. For example, is this particular case special? What are the details of it not breaking anything? Is there some scenario where it would break something? At least, readers of this answer ought to be given the (detailed) information.
con't - There is a discussion in comments to this answer.
0

Use:

pip3 install --user ipython 

But before you much further, search the Internet_ and learn about "virtual environment" for Python.

2 Comments

Does --user do the same as creating a venv, then installing ipython in that venv? I am just learning about these now. I assume there must be somewhere a default global venv which commands like this operate on?
no. It installs packages in a subfolder of ~/.local/... which is also on your Python search path, with a higher precedence than the system folders. And also, is user-writable, so no need for "sudo". It won't conflict with your system packages, but also won t allow you to have different library versions across your projects: it would be better to have an explicit virtual env anyway.
0

Based on PEP 668, you can create a new virtual environment to install ipython (or any other python package in your system) or use pipx.

To install pipx, run:

sudo apt install pipx -y pipx ensurepath 

Install the package from PyPI, like this:

pipx install ipython 

Reload your terminal, and check your installation:

ipython --version 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.