简体   繁体   English

导入“numpy”无法解决 Pylance

[英]Import "numpy" could not be resolved Pylance

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:当我运行代码时,它显示以下错误:

在此处输入图像描述

I have installed NumPy, successfully, but still getting this warning.我已成功安装 NumPy,但仍然收到此警告。 How can I get rid of this?我怎样才能摆脱这个?

Try this in VSCode IDE:在 VSCode IDE 中试试这个:

(1) ctrl-shift-p (1) ctrl-shift-p

(2) In search box, type python and then select Python: Select Interpreter (2) 在搜索框中,输入 python 然后输入 select Python: Select Interpreter

(3) select Python 3.10.4 or any one matches your verion (3) select Python 3.10.4 或与您的版本匹配的任何一个

the problem usually caused by IDE didn't pick up the right interpreter通常由 IDE 引起的问题没有选择正确的解释器

For people who use Visual Studio Code: sometimes happens that import could not be resolve because the Python interpreter is not selected.对于使用 Visual Studio Code 的人:有时会发生无法解析导入的情况,因为未选择 Python 解释器。 In this case ctrl + shift + p ---> Select python interpreter --> Python version installed on the computer本例ctrl + shift + p ---> Select python 解释器 --> Python 电脑上安装的版本

I was using two versions of python.我使用了两个版本的 python。 Then I uninstalled both versions of it and installed the latest version of python 3.10.1 from https://www.python.org/ .然后我卸载了它的两个版本并从https://www.python.org/安装了最新版本的 python 3.10.1。 After this, installed pip Matplotlib and Numpy.之后,安装 pip Matplotlib 和 Numpy。 Everything got sorted out.一切都解决了。

Maybe you have installed it in another env也许你已经将它安装在另一个环境中

  1. Try to change version from python interpreter尝试从 python 解释器更改版本
  2. Try to install python IDE尝试安装 python IDE
  3. Try to uninstall it and install numpy again尝试卸载它并重新安装 numpy

Hope this will fix your issue!!希望这能解决您的问题!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM