How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

by miki dream -
Number of replies: 4

The students get this error


***Run error***
Traceback (most recent call last):
  File "__tester__.python3", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

please help me to fix this in the question editor or in the server where my coderunner runs?

Thank you

In reply to miki dream

Re: How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

by Richard Lobb -
Yes, you need to install numpy (and any other extra modules you might need, such as matplotlib) on the Jobe server your institution is using. Those modules are not part of a standard Python install.

This requires admin-level access to the Jobe server.

The command to install numpy from a command line (running as root) is:

python3 -m pip install numpy
You can ignore any warnings saying you shouldn't run pip as root.
In reply to Richard Lobb

Re: How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

by miki dream -
Thank you Richard for you reply. I'm getting this Error when trying to install this command in my server.
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.
"
I'm not sure what to run now .
Using Ubuntu 23.10 it's a DigitalOcean droplet server.
Appreciate any help/ thankyou
In reply to miki dream

Re: How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

by Richard Lobb -
Oof, this is a recent "improvement" to pip.

Try instead:

sudo apt install python3-numpy
and, if you want it,

sudo apt install python3-matplotlib

In reply to Richard Lobb

Re: How TO FIX :" import numpy as np, ModuleNotFoundError: No module named 'numpy'

by miki dream -
Thank you very much. That helped us.