Pycharm auto relative imports

Laimonas Sutkus picture Laimonas Sutkus · Feb 9, 2018 · Viewed 7.9k times · Source

Whenever you use autoimport provided by PyCharm it generates an absolute path import. i.e.

from my_package.my_subpackage import my_thing

instead of

from .my_subpackage import my_thing

Is there a setting to use relative imports instead of absolute ones when importing a python package?

Answer

ptr picture ptr · Feb 9, 2018

It appears currently there is no way to change the import style for auto-import feature to use relative imports. The only style changes you can make to import statements are how the absolute imports are structured:

enter image description here

(The Jetbrains/PyCharm settings search functionality is excellent by the way).

The same thing happens when refactoring, it's definitely an option I'd like to see added.