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

I've got a directory structure like

parent/
  bin/
  src/
    x/
      y/
        a/
        b/
          file1
          file2
        c/
        file3

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?
0
Figured it out– set y/ as a source directory.
0
If x and y are Python packages (so src is your actual source directory) then you should import x from file2.py 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.
0

请先登录再写评论。