Import "numpy" could not be resolved Pylance

Viewed 8246

I have wrote the following code:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 5, 100)
y = x**2
plt.plot(x, y)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("graph of $x^2$")
plt.show()

When I run the code, it shows the following error:

enter image description here

I have installed NumPy, successfully, but still getting this warning. How can I get rid of this?

4 Answers

Try this in VSCode IDE:

(1) ctrl-shift-p

(2) In search box, type python and then select Python: Select Interpreter

(3) select Python 3.10.4 or any one matches your verion

the problem usually caused by IDE didn't pick up the right interpreter

I was using two versions of python. Then I uninstalled both versions of it and installed the latest version of python 3.10.1 from https://www.python.org/. After this, installed pip Matplotlib and Numpy. Everything is fine now.

For people who use Visual Studio Code: sometimes happens that import could not be resolve because the Python interpreter is not selected. In this case ctrl + shift + p ---> Select python interpreter --> Python version installed on the computer

Maybe you have installed it in another env

  1. Try to change version from python interpreter
  2. Try to install python IDE
  3. Try to uninstall it and install numpy again

Hope this will fix your issue!!

Related