0

So my file system looks something like this

/projects
--setup.py
--setup.cfg
--/app
--/--__init__.py
--/--app.py
--/--file_with_class.py

In my app.py I import file_with_class.py, but when I use setup to install my module with pip install . and try running it, I get this error: ModuleNotFoundError: No module named 'className'

supose file_with_class.py contains a class named className

I'm importing this class in app.py like this:

from file_with_class import className

Also, when executing app.py on its own it works perfectly, the problem comes when creating the package with setuptools and after installing my own package, trying to run it.

2 Answers2

0

You can use relative import:

from . import class
jeremy302
  • 798
  • 6
  • 10
0

You should use either relative, or fully qualified module name imports:

from . import class

# or, probably better:
import app.class
from app import class

BTW, class is a reserved word. Not sure if this was the module's name in your original code, but if it was you probably want to avoid it.

shevron
  • 3,463
  • 2
  • 23
  • 35