为什么 PyCharm 在某些 Numpy 导入时会给出未解决的参考错误? [英] Why does PyCharm give unresolved reference errors on some Numpy imports?

查看:25
本文介绍了为什么 PyCharm 在某些 Numpy 导入时会给出未解决的参考错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PyCharm 中的以下行被动态检查标记为每个导入的未解决的参考错误.(它们带有红色下划线.)

The following line in PyCharm is flagged by on-the-fly inspection with unresolved reference errors for each import. (They are underlined red.)

from numpy import tan, arcsin, arccos, arctan

但是,以下导入不会导致任何错误/警告:

However the following imports do not cause any error/warning:

from numpy import sin, cos, arctan2, sqrt, cross, pi

我使用这些导入的代码运行良好,没有任何错误或警告.我通常依靠 PyCharm 的红色错误作为我的代码已损坏且无法运行的警告,但在这种情况下 PyCharm 是错误的.

The code in which I use these imports runs fine without any errors or warnings. I generally rely on PyCharm's red errors as a warning that my code is broken and will not run, but in this case PyCharm is wrong.

为什么 numpy 的一些函数能被 PyCharm 的内省识别而另一些不能?

Why are some of numpy's functions recognized by PyCharm's introspection and others aren't?

当前版本:

  • Windows 7 64 位
  • Python 2.7.5
  • PyCharm 3.1.2
  • Numpy 1.8

谢谢!

推荐答案

你得到这个的原因是因为 PyCharm 的静态分析.现在,Python 所做的是使用静态骨架(有些是预先生成的,有些是生成的)来为您提供分析.看看这里的预生成骨架 -> https://github.com/JetBrains/python-skeletons

The reason you are getting this is because of PyCharm's static analysis. Now, what Python does is use static skeletons (some are pre-generated and some are generated) to give you the analysis. Take a look at the pre-generated skeletons here -> https://github.com/JetBrains/python-skeletons

这可以通过启用以下功能来解决:

This might be solved, by enabling the following:

但是,如果这不起作用:

However, if that does not work:

这将阻止错误,它将显示为行上方的注释.

which will block off the error, it will appear as a comment above the line.

这篇关于为什么 PyCharm 在某些 Numpy 导入时会给出未解决的参考错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆