0

I have a python project that looks like this:

appname/
   __init__.py
   cli.py
   compute_signature.py
   utils.py
   test/
       __init__.py
       test_compute_signature.py

How should I write my imports? Currently, in cli.py I have

from compute_signature import # stuff
from utils import # stuff

And when I run python cli.py it imports correctly. However, when I run pylint cli.py, it says it's unable to import these modules. If I change the imports to:

from hex_configuration.compute_signature import # stuff
from hex_configuration.utils import # stuff

then pylint succeeds, but actually running the script fails.

What is the correct way to import these files?

  • Move cli outside of the modul/app and use from appname.compute_signature import Foo Use this also in files inside the modul – Christoph Nov 04 '21 at 19:18
  • Do any of the methods in [this answer](https://stackoverflow.com/a/3065082/6768111) (or other answers in that question thread) work for you? – Sparrow1029 Nov 04 '21 at 19:18

1 Answers1

0

user2672844's suggestion worked for me.

My structure now looks like this:

appname/
   __init__.py
   cli.py
   hex_configuration/
       compute_signature.py
       utils.py
   test/
       __init__.py
       test_compute_signature.py

And in cli.py, I import like this:

from hex_configuration.compute_signature import # stuff
from hex_configuration.utils import # stuff

I guess the main method can't be a part of the module that it wants to import from.