[英]ModuleNotFoundError: No module named 'xxx' with my custom type in Visual Studio code
I try to run the code below by clicking the red box Run Python File
in the screenshot below:我尝试通过单击下面屏幕截图中的红色框
Run Python File
来运行下面的代码:
car_client.py car_client.py
from MyLib.car import Car
car = Car()
print(car.get_name())
But I get the error below:但我收到以下错误:
from MyLib.car import Car
ModuleNotFoundError: No module named 'MyLib'
ModuleNotFoundError:没有名为“MyLib”的模块
car.py汽车.py
class Car:
def get_name(self):
return 'BMW'
To make it a module, you need to define an __init__.py
file.要使其成为一个模块,您需要定义一个
__init__.py
文件。
Documentation: https://docs.python.org/3/tutorial/modules.html#packages文档: https://docs.python.org/3/tutorial/modules.html#packages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.