0

I'm building an installable python package, it's basically a CLI based on docopt and other herbs.

The overall structure is as follows:

README.md
MANIFEST.in
setup.py
grok/
   __init__.py
   module.py
   other_module.py
   main.py

On my main.py I have the other modules imported as follows:

main.py

# Imagine the docopt USAGE string here
from .module import something
from .other_module import other_something

# the rest of the logic comes here


The main issue is, I can install the package and use it, but, when I'm changing the code, maybe adding features or fixing a bug, if I try to run it like this:

python main.py -h 

It gives me the following error:

ModuleNotFoundError: No module named '__main__.module'; '__main__' is not a package

I googles a bit and found out that because of the dot on my imports I'm actually referencing __main__, so, I should remove the dots and I should be able to test it the way I intended after that.

I did so, and it worked, I tested all my stuff, and then ran the test suite, as a part of the suite it tests installing the package and run it with -h as a way to smoke-test it, and it failed with the following error:

ModuleNotFoundError: No module named 'module'

Then I re-added the dots to the imports and the test passed.

What am I doing wrong? in theory I should be able to import everything in a way I can execute the installed package and run it on my code for testing without having to change anything.

Any hints?

iferminm
  • 2,019
  • 19
  • 34
  • @YSelf, it is indeed a duplicate, I'm sorry, somehow I didn't get to that answer first. Thanks a lot. Should I close it? or delete it? – iferminm Aug 22 '19 at 14:21
  • The [FAQ](https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled) says close, but don't delete, so people who would formulate the question more like you did (and less like the other question) are more likely to find the question (and therefore answer). – YSelf Aug 23 '19 at 10:05

0 Answers0