Defining custom import aliases for auto import?


If I create a new project (with a blank virtual environment), and add a file that only contains `np.array([1, 2, 3])`, if I haven't imported NumPy yet, PyCharm offers to `import numpy as np`. In particular, PyCharm knows that np is referring to numpy and will add the appropriate import numpy as np.

Is there a way to define my own alias names to be recognized? For example, tensorflow is usually imported as tf. PyCharm doesn't know this by default though, and so doesn't give me the automatic import completion. Any way to do this?

Also notable, if I install another package which has a module named `np` I am no longer offered the `import numpy as np` auto import. For example, if I install `plotly`, now the only auto import options listed for `np` are the ones within `plotly` (e.g., ``). Is there also a way to keep offering the `import numpy as np` option?

Comment actions Permalink

The default library aliases were added with

The problem with numpy auto-import is known, please vote and follow for updates.

Also, I couldn't find a feature request about custom library aliases, so feel free to submit one.

Comment actions Permalink

I have now found this issue, which, although is not explicitly for custom aliases, might eventually result in that implementation.


Please sign in to leave a comment.