Skip to content
Advertisement

Visual Studio: unresolved import ‘numpy’

I am trying to run the code below which requires numpy. I installed it via pip install numpy. However, numpy gets highlighted in the editor with the note unresolved import ‘numpy’. When I try to run it I get the error No module named ‘numpy’. After I got the error the first time I uninstalled numpy and re-installed it but the problem persists.

I am using Python 3.7.8 and NumPy 1.20.2.

The code I am trying to run:

JavaScript

Advertisement

Answer

How did you create your workspace in Visual Studio? Do you have Python development tools installed with Visual Studio? Did you create a “Python application” as your project template?

If so then your project should have a virtual environment created, which you can see in the solution directory. If that is the case do:

  1. Go to “Solution Explorer” Tab >
  2. Find “Python Environments”
  3. Find your active env. For me there was only one called “Python 3.9 (global default)”
  4. Right click and select “Manage Python Packages…”

There it should list all the packages installed and versions. If numpy is not there, just type “numpy” in the search box and click the suggests install option: “run command: pip install numpy”.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement