Numpy is not working

It’s not a question of which is right or best. This is the list of places the Python interpreter will look for imports. All we’re doing here is exploring why numpy is not found.

I can see from this and the answer you gave James @jamestwebber that pip has installed numpy in one of these places (the one with site-packages in the name). I’m fairly confident that if you had typed import numpy in the Python session you started at the console it would have worked.

Now, when you answer Paul @onePythonUser , I can see that you are running his suggested script in PyCharm, and as Jeremy @jkloth effectively points out, PyCharm is running your code in a virtual environment, which is a sort of isolated installation of Python just for your project. It has its own site-packages, not the one where pip installed numpy. I would guess the place where import numpy didn’t work for you was in a PyCharm project. That’s why I wrote:

It seems annoying at the moment, but it is in fact very useful to have your project isolated like this, so it works the same way whatever you may have installed for some other project.

The easy solution is to get PyCharm to install numpy for that project. At the place where you import numpy in the PyCharm editor, without installing it for the project, it should catch your mistake and if you hover the mouse on the red underline, it will offer to do the installation, like this:
image

By the way, if you’re posting code or error messages, people prefer that you not use an image, but paste the code than mark it up using the “</>” button or by typing back-ticks. I used an image here so you could see the hover.

1 Like