# numpy resolution problem Follow

Answered

PyCharm is failing to resolve imports from numpy. If I write:

ImportFail

import numpy as np import numpy.core.umath as np2 def my_exp(t): return np.exp(t) def my_exp2(t): return np2.exp(t)

PyCharm resolves np2.exp() correctly but fails to find np.exp() with a "Cannot find reference 'exp' in __init__.py".

After working out that the __init__.py in question is the numpy one (it makes sense but there are a lot of __init__.py s floating around) I think I have narrowed the problem down to how the numpy skeleton is created. The original numpy __init__.py is quite elaborate and imports several submodules into the main namespace. In particular there is the line:

__all__.extend(core.__all__)

which is I think responsible for np.exp() running. However despite the numpy __init__.py being 216 lines long, the stub in the skeleton is empty. Is there a way around this? I use numpy in practically all my code and it is for sprawling libraries like this that code completion and resolving on the fly are most useful so I would really like to know how to fix this.

I'm using PyCharm 4.0.4 Professional with numpy 1.9.1 in an Anaconda virtual environment. The interpreter seems to work correctly, PyCharm finds the correct packages in the correct locations and the normal np.exp works from the console.

EDIT: So I've looked a bit further into skeletons and am more confused but possibly closer to knowing how to fix the problem. The GitHub repository for python skeletons has a non-empty skeleton for numpy's __init__.py which dates to July last year but references version 1.8. It seems that I should clone the github repository and edit the skeleton and can probably manage to do that if there is only one numpy __init__.py but if that were the case, how have I got an empty one? Is something picking out versions? I have now checked that the github skeletons-helpers version of the numpy __init__.py is in my folder but am not sure how to make it, and therefore any update I might make, available to my project which is referring to an empty file numpy/__init__.py stub.

EDIT EDIT: This appears to be the same issue as bugs PY 13124 and PY 14971. The former of which has been open since May last year.

EDIT EDIT EDIT: And also PY 11316 from November 2013

Please sign in to leave a comment.

on lines 181 and 182

or

online 208.

So the more complicated "core" import statement is a completely ordinary import which works while calling numpy.exp involves a much more complex import process which hasn't translated to successful code navigation in the binary skeletons. I believe I am running exactly the same code in each case but the normal invocation fails as described as far as PyCharm code analysis is concerned.

this is related to PY-11316 and will be fixed in next PyCharm release

This bug appears to be back with Intellij IDEA ULTIMATE 2017.3.

Code inspection can't find reference 'arange', 'dot', 'maximum', 'sqrt', 'square', 'zeros', etc in '__init__.py'

Same here, the bug is back and it makes the code hard to clean, as warnings are showing up all the time.

Hi all! Please vote & comment for PY-23521. Unfortunately, I had not much luck reproducing it so any tips are greatly appreciated!

Same issue here with arange - PyCharm 2018.1

I, too, have the same issue with np.arange on PyCharm Professional 2018.2.5. Is this ever going to be fixed? It is so annoying.