0

My project structure is:

APP(dir)

  app(dir)

     model(dir)

        metric_data.py

     __init__.py

     app.py

  setup.py

When I'm running app.py with import statement of

from model.metric_data import MetricData

MetricData is a class, I'm able to successfully run the application retrieving data from metric_data.py file. But when I build it as a package and then try importing package app

from model.metric_data import MetricData

this statement is failing. Can anyone help me with the issue

here, I looked on the relative import part and tried but it didn't work.

cizario
  • 3,995
  • 3
  • 13
  • 27
zuana
  • 23
  • 5
  • Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – It_is_Chris Feb 22 '22 at 15:29
  • I have gone through this and tried too but somehow was not able to get it done correctly. – zuana Feb 22 '22 at 15:33
  • What about this one? https://stackoverflow.com/questions/67268607/issue-with-find-in-setup-cfg-modules-are-not-seen-in-path/70567192#70567192 – Davide Laghi Feb 22 '22 at 15:45

1 Answers1

0

Try to create a __init__.py file in the model directory.

TAN
  • 43
  • 6
  • I have __init__.py inside model directory, I have one more file prac.py inside my app dir which I imported using (from .prac import func) and it worked but how do we do it for file residing inside model dir here – zuana Feb 22 '22 at 15:58
  • this is my setup.py from setuptools import setup, find_packages setup( name="app", version="0.1", description="some descr", # license='', # url=' ', packages=["app"], author="Nishant Chaubey", author_email="nchaubey@gmail.com", install_requires=[], ) – zuana Feb 22 '22 at 16:00
  • do I need to add anything in setup.py – zuana Feb 22 '22 at 16:01
  • @NishantChaubey Maybe you could have a check with your current work directory. If you use `from model.metric_data import MetricData`, your work directory must be `app`, otherwise `ModuleNotFoundError: No module named 'xxx'` will occur. – TAN Feb 22 '22 at 16:08
  • You also could put your error logs up for troubleshooting. – TAN Feb 22 '22 at 16:09
  • I figured it out, I had to add app.model too as package in setup py and it worked, thanks to all. – zuana Feb 22 '22 at 17:50