numpy is not a part of the Python Standard Library, and isn't installed by default on most Linux distros, including WSL, which is an Ubuntu terminal environment. For this reason, you can't just import it without first installing the package.
There are two ways that you can install additional Python packages to WSL. The first is to install directly from Ubuntu repositories:
$ sudo apt install python3-numpy
$ python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
The repositories won't contain every single Python package, only those that have been packaged for Ubuntu. These will all be very stable, however.
The second way is to use the pip
package manager, which must itself be first installed from the repositories:
$ sudo apt install python3-pip
$ pip install numpy
$ python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
pip installs packages from the Python Package Index, which contains almost every Python package under the sun. Many of these are just in development, don't work, or are abandoned, but all the mainstream packages are there too.
It doesn't matter much which method you choose, but it is tidy to pick one, and stick with it for all your Python packages. Nothing will stop you from installing the same package from both sources, which can be different versions.
The reason that this works without issue in jupyter is probably because it is running inside an environment, probably setup with anaconda, which already contains these packages.