我无法导入模块,即使它们位于我现在正在使用的同一目录中(E:\ Python Projekti \ Python Crash Course)。我试图在这里找到解决方案,我以为我是通过.module_name找到的,但仍然无法正常工作。
我尝试了.module_name方法,它为我提供了包含所有可能模块的下拉菜单,但最后,它给了我终端错误。
from .restaurant_module import Restaurant
restaurant = Restaurant('Madera', 'Soulfood')
restaurant.describe_restaurant()
Traceback (most recent call last):
File "E:/Python Projekti/Python Crash Course/Chapter
9/imported_restaurant.py", line 1, in <module>
from .restaurant_module import Restaurant
ModuleNotFoundError: No module named '__main__.restaurant_module';
'__main__' is not a package
我会尝试Jammy的建议:import restaurant_module
或尝试在同名目录中添加一个空白文件,__init__.py
然后查看是否可行。
编辑:此仓库可以帮助您构建结构吗?https://github.com/ehmatthes/pcc
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句