-1

I'm having a hard time trying to import modules created inside a project.

The structure of my project is as follows:

myapp/calcs/__init__.py
myapp/calcs/calculations.py
myapp/tests/__init__.py
myapp/tests/test_calcs.py

Inside test_calcs.py, I have the following import statement:

from calcs import calculations as clc

However, I am getting this error:

ModuleNotFoundError: No module named calcs

I can't understand why I am having this error as I have included an init.py file inside calcs which should make it act as a module.

2 Answers2

1

I also found this part of python extremely confusing. You basically need to make your project an installable package and do an editable install of it in your environment to import your modules this way. I would recommend this youtube video for a great walkthrough on the process, you only need to watch 2:36-8:36 for this topic specifically but the whole video is quite useful. Best of luck.

Jesse
  • 73
  • 7
0

The first three answers in this thread describe how you can solve this pretty well!

Short version:

  • change from calcs import calculations as clc to from ..calcs import calculations as clc
  • start a terminal session in the parent folder of myapp
  • run python -m myapp.tests.test_calcs.py
ffrosch
  • 899
  • 6
  • 15