I try to run the code below by clicking the red box Run Python File
in the screenshot below :
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’
car.py
class Car:
def get_name(self):
return 'BMW'
2
Answers
To make it a module, you need to define an
__init__.py
file.Documentation: https://docs.python.org/3/tutorial/modules.html#packages
Add the following to the top of the code in the car_client.py file:
and modify the import as
the code will work fine