Home > OS >  Why can I use NumPy with Python 3.8 which was preinstalled but not with Python 3.9 which I installed
Why can I use NumPy with Python 3.8 which was preinstalled but not with Python 3.9 which I installed

Time:01-21

I installed Ubuntu 20.04, and python3 (3.8) is installed by default. To install python3.9, I executed:

sudo apt install python3.9

Thus, I have two versions of Python at my laptop: 3.8 and 3.9.

I'm trying to launch the simple script:

import numpy

With Python 3.8 it works correctly. But, when I interp my script by Python 3.9 the error occurs:

enter image description here

How to solve this problem?

I've already tried to update numpy using pip, nothing has happened.

pip3 install numpy --upgrade

CodePudding user response:

Likely what is happening here is, because you have 2 versions of python installed, your pip3 command is only installing things for one of the versions, 3.8 in this case.

Specifying the python version you want to run your command with will help solve this issue.

For example,

python3.9 -m pip install numpy

or

python3.8 -m pip install numpy

CodePudding user response:

You can install a package for a specific version of Python with

python3.9 -m pip install numpy

For a more consistent python environment look at python venv or a container.

  • Related