Doubt about installing package

I am trying to work on a code which supports numpy<2.In my jupyter notebook if i install “pip install numpy” gives me a version number of 2.3.2 and “!pip install numpy” gives me a version number of 1.26.4. By default it takes the higher version and my code is not supporting.How can i tell to consider “!pip install numpy” version for my code to work?

If you are doing this locally, you’d ideally want to be doing this in a virtual environment.

Did you try running in your active Jupyter .ipynb file?:

%pip install --force-reinstall numpy==1.26.4

Why that?

First, you’d want to see the answer here to ‘Installing specific package version with pip’ because in general this type of specifying version number when installing isn’t particular to Jupyter.

But since you are running it in Jupyter so you should be using the magic symbol in front of pip.
Why the magic symbol?..
You should read my comments here under ‘Context’. Using the exclamation point with pip is not current best practice inside Jupyter and could cause you to introduce issues that you would have avoided if you had used %pip.


More details may help you follow what was going on here:

In modern Jupyter, tpyically auto-magic is on and so running pip install numpy without any symbol is therefore equivalent to %pip install numpy. In other words, without a symbol in front of pip or conda, generally Jupyter will try the magic symbol behind the scenes. It is though best to be explicit so you and others reading what you did are clear.
And because you weren’t specifying a version it was installing the current version.

I am able to install the required version with %pip install numpy==1.24.4 but for %pip show numpy gives me 2.3.2 version.I have also attached the code I am working on so that you can help we with resolving the error as well.Screen Recording 2025 08 18 234235

I’m concerned because in your screen recording I see ‘anaconda’ in the path that scrolls by very fast.
You shouldn’t then be using pip here is my guess.
If you are using Anaconda/conda, you should only ever use %conda install henceforth as when you install Anaconda/conda you choose to make that your primary package manager. (Only pip use should be reserved for attempts when a package isn’t available via conda`.) Plus, it has some environment managing patterns you need to adhere to as you work with it.

If you are using Anaconda Distribution locally or in the Anaconda cloud, you’ll are better off making the environment outside of Jupyter and then connecting to it properly.
Are you linking the environments correctly to Jupyter? See here.

%conda install run inside a Jupyter notebook can often work in MyBinder sessions but making the environment in a terminal is best when running locally or in the Anaconda Cloud, in my experience.

By the way, then with conda, the syntax is different for specifying a version, see here.