Fix: Import “numpy” Could Not Be Resolved (Pylance, VS Code)

Import "numpy" could not be resolved is a Pylance warning in VS Code. It means the Python interpreter VS Code is using doesn’t have NumPy installed. Select the right interpreter, or install NumPy into the one that’s selected:

Ctrl+Shift+P  ->  Python: Select Interpreter  ->  pick your .venv
python -m pip install numpy        # run in the VS Code terminal

Pylance is built on Pyright, so I reproduced the exact message with the Pyright command-line tool and Python 3.12.5, then fixed it the same way you would in VS Code.

I’ll show why the warning appears, the two fixes for packages like NumPy, the fix for your own modules in another folder, and what to try when it still won’t go away.

Why does Pylance say import numpy could not be resolved?

Pylance looks for packages in the interpreter selected for your workspace. If NumPy is installed somewhere else, such as your global Python or a different venv, Pylance can’t see it:

import numpy as np

prices = np.array([19.99, 4.50, 102.00])
print(f"total: ${prices.sum():.2f}")

Output:

c:\pyguides\store_report.py
  c:\pyguides\store_report.py:1:8 - error: Import "numpy" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 informations
Traceback (most recent call last):
  File "C:\pyguides\store_report.py", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'
Command Prompt output of Pyright reporting Import numpy could not be resolved reportMissingImports, then the script failing with ModuleNotFoundError
Pyright (Pylance’s engine) gives the same message you see in VS Code, and running the script with that interpreter fails too.

When the script also fails to run, the package really is missing from that environment. If it runs fine but Pylance still complains, VS Code is pointed at a different interpreter than the one in your terminal.

Fix 1: Select the right interpreter in VS Code

  1. Press Ctrl+Shift+P (Cmd+Shift+P on a Mac) and run Python: Select Interpreter.
  2. Pick the environment that has NumPy, usually .venv in your project folder.
  3. Check the interpreter shown in the bottom-right of the status bar.
  4. If the squiggle stays, run Developer: Reload Window.

Not sure which Python you’re using? python -c "import sys; print(sys.executable)" in the VS Code terminal tells you. For managing environments, see Python virtual environments.

Fix 2: Install NumPy into the selected interpreter

If the right interpreter is selected but NumPy isn’t in it, install it there. Using python -m pip from VS Code’s terminal guarantees the same environment:

uv pip install --python .venv-store\Scripts\python.exe numpy
pyright --pythonpath .venv-store\Scripts\python.exe store_report.py
.venv-store\Scripts\python.exe store_report.py

Output:

Using Python 3.11.17 environment at: .venv-store
Resolved 1 package in 20ms
Installed 1 package in 527ms
 + numpy==2.4.6
0 errors, 0 warnings, 0 informations
total: $126.49
Command Prompt output of installing numpy into a project virtual environment, Pyright reporting 0 errors, and the script running
After the install, Pyright reports 0 errors and the script prints the total.

There’s more on installing correctly in how to install a module in Python and ModuleNotFoundError after pip install.

Fixing could not be resolved for your own modules

The same warning appears for your own files in another folder, like shared/. Tell Pylance where to look with extraPaths; here it’s a pyrightconfig.json, which Pylance also reads:

from pricing import add_tax          # pricing.py lives in the shared\ folder

print(f"${add_tax(100.00):.2f}")

Output:

c:\pyguides\checkout.py
  c:\pyguides\checkout.py:1:6 - error: Import "pricing" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations
Command Prompt output of Pyright failing to resolve a local module in shared, then passing after adding extraPaths to pyrightconfig.json
Before: could not be resolved. After adding "extraPaths": ["shared"]: 0 errors.

A folder named src is searched automatically, so it needs no setting.

In VS Code you can set the same thing as "python.analysis.extraPaths": ["shared"] in .vscode/settings.json. This only fixes the editor; to run the code, Python itself also needs to find the folder, as explained in Python import from another directory.

Still seeing could not be resolved in VS Code?

SymptomTry this
Code runs, Pylance still underlinesSelect Interpreter again and reload the window
Yellow “reportMissingModuleSource”Type stubs were found but the package isn’t installed; install it
Only in one folder of a multi-root workspaceSelect the interpreter per folder
Package installed with condaPick the conda environment in Select Interpreter
Just started a new venvWait for Pylance to finish indexing, then reload

If NumPy imports but crashes with a different message, see numpy.core.multiarray failed to import.

Related setup guides for VS Code and Python:

Frequently asked questions

Why does VS Code say import numpy could not be resolved?

Pylance is checking an interpreter that doesn’t have NumPy. Select the right interpreter, or install NumPy into the selected one.

My code runs but Pylance still shows the error. Why?

The terminal and VS Code are using different interpreters. Run Python: Select Interpreter and choose the one your terminal uses.

How do I fix could not be resolved for my own module?

Add the folder to python.analysis.extraPaths in VS Code settings, or to extraPaths in pyrightconfig.json.

Is reportMissingImports an error in my code?

No. It’s an editor warning about where packages are installed. Your code may still run if the right interpreter is used.

Can I just hide the warning?

You can add # type: ignore to the line, but fixing the interpreter is better since it also restores autocomplete.

Where are Pylance settings documented?

See Python settings reference in the VS Code docs.