How to get Pycharm to resolve "downward" file paths?

I've got a directory structure like


I'm trying to import functions from file2 into file1, but pycharm keeps giving me import errors and I have no idea how to solve this. Pycharm is able to traverse up, so I can say "from .file2 import x" but not down, so I can't say from y.b.file2 or anything like that.

How can I fix this?
Comment actions Permalink
Figured it out– set y/ as a source directory.
Comment actions Permalink
If x and y are Python packages (so src is your actual source directory) then you should import x from using from x.y.b.file2 import foo (absolute import) or from .file2 import foo (relative import).

If you mark y as the source directory and if it is not the case for your project, you will not be able to run it outside of PyCharm, because your Python path will not include path to y.

Please sign in to leave a comment.