Skip to content
Advertisement

Not able to import a class from a another package in python

JavaScript

I’m trying to import a class from somename.py into nicename.py. At first I created the the __init__.py file and left it empty. Then I wrote (in nicename.py):

JavaScript

and I also tried the command without double points at first.

It returns:

ModuleNotFoundError: No module named ‘getdir’

Advertisement

Answer

Maybe not the most elegant but you can add the path in sys.path before importing getdir:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement