Home > Mobile >  Can't import a class from a python package
Can't import a class from a python package

Time:08-08

I created a private python package with this structure:

   python_package
       utils
          __init__.py
          module1.py
          module2.py

And inside the module1.py file there is a class Class1

Now when I download this package in another project using pip, I can't import Class1 using

from utils import Class1

Am I missing something ?

Also the __init__.py file contains the following lines :

from .module1 import *
from .module2 import *

CodePudding user response:

Probably in another project you need to import it like this:

from python_package.utils import Class1

CodePudding user response:

try this if you are not able to access the class directly

import filename
object=filename.class1()
  • Related