对不起,这绝对是重复的,但我找不到答案。我在Python 3个工作,这是我的应用程序的结构:如何导入Python文件?
/home
common.py
australia/
new-south-wales/
fetch.py
我在home/
目录,运行fetch.py
。如何在该脚本中导入common.py
中的函数?
我已经设置了fetch.py
如下:
from common import writeFile
,但我得到了以下错误:
File "australia/new-south-wales/fetch.py", line 8, in <module>
from common import writeFile
ModuleNotFoundError: No module named 'common'
如果我只是做python -c "from common import writeFile"
我没有看到一个错误。
不应该翻译look in the current directory for modules?
你错过了一个'__init __ py'为模块。 https://docs.python.org/3/tutorial/modules.html#packages –