pythonclionauto-import

Configuring CLion python root directory for auto-imports


My project has a directory structure like:

PROJECT_ROOT/
             src/
                 foo/
                     bar.py

I want my imports to look like:

from foo import bar

But IntelliJ's auto-import is writing:

from src.foo import bar

How do I tell IntelliJ that it should generate its imports relative to PROJECT_ROOT/src/ rather than relative to PROJECT_ROOT/?


Solution

  • The root problem behind my question was that the "Mark Directory as" option was not available in the project pane. It turns out that for some reason this option will only present itself if a CMakeLists.txt file exists. By adding a barebones cmake file, the "Mark Directory as" option became available, and I was able to mark the src directory as a source root. See here for details.