pythonubuntu-20.04

Why can I use NumPy with Python 3.8 which was preinstalled but not with Python 3.9 which I installed in addition?


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

Solution

  • 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