Reputation: 304
My OS is Ubuntu 22.04.4 LTS. The "pip list" command tells that I have the NumPy 1.21.5. But I need a newer version of the NumPy.
I am trying to install the NumPy package whith next command:
pip install --upgrade numpy==2.1.2
But here is an error:
<...>
Run-time dependency python found: NO (tried pkgconfig, pkgconfig and sysconfig)
../meson.bould:41:12: ERROR: python dependency not found
I find that I must install -dev package. So I do that:
sudo apt install python3-dev
...but the NumPy installation error is still there.
What shall I do to upgrade the NumPy?
Upvotes: 2
Views: 289
Reputation: 5113
What's most likely going on here is: You are currently using the system version of both python
and numpy
. With "system version" I mean a version installed as an apt
package (so via Ubuntu's package management) as opposed to being installed as a pip
package (so via Python's default package manager).
What is usually not a good idea (and often simply does not work, as you experienced), is trying to update a Python package with pip
that has been installed with apt
.
The better idea, in my opinion, would usually be: keep the Python environment that you want to work with and the system's Python environment separate. This separation can happen on different levels:
python
, but might want to install your own version of numpy
. This can be achieved, for example, using a virtual environment, as has been suggested in AKX's comment. The article linked there is a good deep-dive into the subject and also might provide you with further motivation as to why to choose this approach. The answer of 9769953 describes the necessary steps of setting up a virtual environment and installing numpy
there.python
version separate from the system version of python
. This can be achieved, for example, using anaconda
/miniconda
/miniforge
. With conda
and its ecosystem, you have yet another package management tool and repository available, which is also Python-focused, but includes more than Python packages. The article from AKX's comment has a brief section on conda
as well.There are plenty more options starting from there (obligatory xkcd cartoon, which, though being outdated, still captures the essence of the situation I think), and it may be hard to judge which setup will be best for your needs. For the pros and cons of virtual environments vs. conda
in particular, you might also want to have a look at the answers to this related question that compares virtualenv
(a superset of venv
) to conda
.
Upvotes: 2
Reputation: 12182
Use a virtual-env first
cd <to-your-working-directory>
python3 -m venv venv
source venv/bin/activate
Your prompt will change accordingly, to indicate you are using the virtual environment. Any next session (either a new terminal, new terminal tab or simply a new login) only requires the source venv/bin/activate
in that working directory, not the python -m venv
part.
Now install NumPy
python3 -m pip install numpy
and install whatever else you need.
This will install a newer NumPy in that virtual environment; it is shielded from the system Python, so it can't break your system.
Now do your analysis / coding / whatever you want to do.
Note that I have explicitly used Python 3 here. The python
command (and similar the pip
command) may refer to Python 2, and that won't work with newer packages such as NumPy 2. Using python3
explicitly will ensure you don't accidentally use Python 2.
Usuing python3 -m pip
in a virtual environment, is technically not necessary anymore(*), but it's a good enough habit to be clear what is going on, that I'll leave it like that.
(*) within a virtual environment, python
and pip
will refer to the Python you used to create that v-venv, which was the system Python 3.
Upvotes: 2
Reputation: 52
pip install <package>
. If you see a newer version on pypi but is not being installed by pip, it's because your python version does not support that numpy version. Confirm if it is supported for your python version or upgrade your python version.Upvotes: -2
Reputation: 147
The command you're using has a syntax error. It should be
pip install --upgrade numpy==2.1.2
Notice the ==
instead of =
. This might fix it.
Upvotes: 0