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

2024-09-30 01:34:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法导入模块,即使它们与我现在使用的目录相同(E:\Python Projekti\Python Crash Course)。我试图在这里找到解决方案,我想我找到了它与.module\u名称,但它仍然不起作用

我尝试了.module\u 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

Tags: 模块方法namefromimport目录名称main

热门问题