Can't import numpy module into python file, but it works with terminal

372 Views Asked by At

On Ubuntu I have python 3.6.9

I created new project using PyCharm, into project folder there is venv folder. When I open venv folder in terminal and do:

python3
import numpy

It works, no any error.

But when I create some file in that venv folder using PyCharm, and try in this file:

import numpy 

then I get ModuleNotFoundError: No module named 'numpy' error.

Why can't import module into file? module obviously installed because I can import that using terminal (folder is same for both cases).

What is my mistake ?

3

There are 3 best solutions below

1
On BEST ANSWER

Pycharm uses virtual environments for serving modules, so you will have to download the package from either the GUI or by activating the virtual environment in the terminal and then doing the pip install.

if you want to do it from the GUI you can check the official tutorial. (Working and tested)

To do it manually, first to activate the environment in linux go wherever the venv folder is and type source venv/scripts/activate (to activate) and then you'll be able to do pip install numpy. (Not tested but it should work)

0
On

Could you share your Pycharm configuration? Some extra steps are needed in Pycharm to configure venv, otherwise it will just take your normal interpreter site-packages.

Take a look at the Pycharm help page: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html#existing-environment

0
On

looks like you need to install numpy through pip3. Also, check which version of python is running in pycharm.