我正在使用python 3.6.5和Pycharm。 我有两个" .py"名为make_pizza.py和pizza.py的文件。下图显示了两个文件的路径:
两个.py文件的详细信息如下所示: 1)pizza.py:
def make_pizza(size,*toppings):
"""Describe the pizza you want to make"""
print("\nMaking a " + str(size)
+ "-inch pizza with the following toppings:")
for topping in toppings:
print("- " + topping)
2)making_pizza.py:
import pizza
pizza.make_pizza(16, 'pepperoni')
如上所示,我想导入模块" pizza.py" in" making_pizzas.py"并使用" make_pizza"功能。但是,当我运行" making_pizza.py"时,它将无效并且会出现错误:
Traceback (most recent call last):
File "C:/Softwares/Python3.6/Project0/making_pizzas.py", line 1, in <module>
import pizza
ModuleNotFoundError: No module named 'pizza'
我确定我将这两个.py文件放在一个名为&#34; Project0&#34;的文件夹中,并将文件夹路径标记为Sources Root。但错误仍然存在。