gpt4 book ai didi

python - 无法导入模块,即使它们与我正在使用的文件位于同一目录中

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:24 25 4
gpt4 key购买 nike

我无法导入模块,即使它们位于我现在工作的同一目录中(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

关于python - 无法导入模块,即使它们与我正在使用的文件位于同一目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57333107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com