0

I have the folllowing folder structure on my python project:

enter image description here

As I understand from this link that explains a python file structure my whole python project will run from the bin/rain_it.py. The code inside this file is the following:

from main import main_function
main_function()

Where my main_function is defined in the main.py file which is defined as follows:

from rain_it import hardware_manager

def main_function():
    print("Hello World!")
    cpu_serial = hardware_manager.get_serial_number()
    print(cpu_serial) 

When I try to run directly from the rain_it.py file, I get the following error:

Traceback (most recent call last):
  File "C:\rootdirectory\rain_it\bin\rain_it.py", line 6, in <module>
    from main import main_function
  File "C:\rootdirectory\rain_it\rain_it\main.py", line 6, in <module>
    from rain_it import hardware_manager
  File "C:\rootdirectory\rain_it\bin\rain_it.py", line 6, in <module>
    from main import main_function
ImportError: cannot import name 'main_function'

However, if I run from the main.py there is no error on the import from the hardware_manager. HOw can I solve this?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
luisgepeto
  • 763
  • 1
  • 11
  • 36
  • You have a circular import; `main` imports `rain_it` which imports `main`. Try to avoid this; your `rain_it` module has not yet defined the `main_function` when it is importing the `main` module again. – Martijn Pieters Aug 01 '15 at 16:30
  • Is this because the rain_it directory name is duplicated? – luisgepeto Aug 01 '15 at 16:31

0 Answers0