问题描述
通过实时检查标记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.
为什么PyCharm的内省功能会识别numpy的某些功能,而其他功能却不能?
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导入中会给出未解决的参考错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!