0

I have a project directory structure as follows:

rootdir/
somefile.py
- proj/
  - __init__.py
  - __main__.py
  - file1.py
  - file2.py

file2 has an import, from file1 import some_module

When I am in rootdir and I call something like import proj.file2.bla_bla as bla_bla from somefile.py

I get an error like

error in file2

cannot find file1 or no such module such as file1

What do you think is going wrong?

Mert Köklü
  • 2,183
  • 2
  • 16
  • 20
op_lop
  • 1
  • 1
    Possible duplicate of [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – lbragile Nov 26 '19 at 23:55

2 Answers2

0

if you are running the program from rootdir like

python3 rootdir/somefile.py

then you can import file1 in file2 as follows

from project.file1 import something

0

I had to make sure that in file2:

from file1 import some_module

becomes

from .file1 import some_module
op_lop
  • 1