无法导入函数python结构

时间:2015-08-01 16:29:21

标签: python python-import

我的python项目中有以下文件夹结构:

enter image description here

据我所知this link that explains a python file structure我的整个python项目将从bin / rain_it.py运行。此文件中的代码如下:

from main import main_function
main_function()

我在main.py文件中定义了main_function,其定义如下:

from rain_it import hardware_manager

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

当我尝试直接从rain_it.py文件运行时,出现以下错误:

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'

但是,如果我从main.py运行,则从hardware_manager导入时没有错误。我可以解决这个问题吗?

0 个答案:

没有答案