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
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.
Why are some of numpy's functions recognized by PyCharm's introspection and others aren't?
Current Versions:
Thanks!
Add "src" as your source root: Now, add Source to your Python Path: Now, Goto PyCharm Menu: Select "File" --> Invalidate Caches / Restart. Import problem is now resolved.
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.
The Python configuration is specified in (at least) two places: Run | Edit Configurations | Python | Python Interpreter
, and File | Settings | Project | Project Interpreter
. My mistake was I did not set the correct Python installation in the File | Settings ...
. Hence, it was referring to a Python configuration that did not have the import installed (e.g. NumPy).
After I set these two locations to point to the same, correct Python installation, I did a File | Invalidate Caches / Restart
, then it was fine.
A third place to check is File | Default Settings... | Project Interpreter
and make sure it matches the other settings.
PyCharm developer posted a workaround for one possible cause of inspection failure:
https://youtrack.jetbrains.com/issue/PY-32029
Gist of it - inspection may fail if you have a venv
folder in the project directory. Right click it, mark directory as excluded.
The following often helps to solve false-positive unresolved references
File | Invalidate Caches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With