I wrote a small python program and again I am struggling with producing a good structure.
A few days ago I read a blog and many other websites, which advise against from a import b
imports and recommend to use always import a.b
"project absolute" path (the whole path from the project root to what I want to import) imports. That as a background.
I included a __main__.py
so that I can run my program with python -m <directory>
, which was another recommendation of someone on stackoverflow in one of the hundreds of python import questions. It is supposed to help keeping code runnable and testable with the same import structure, which was a problem in another project of mine.
Now what I want it, that from anywhere in my system, I can run python -m <dir of my code>
and not only from one directory up the RSTCitations
directory.
How can I achieve that, without:
- python path manipulations (which are a dirty hack)
- changing my imports somehow and getting a not recommended import structure
- doing other dark magic to my code
I want to stick to best practices in organizing my code but still want it to be runnable from wherever I am in the terminal.
Example of fail
When I run the program as described from another directory completely unrelated to my program, I get for example the following error:
/home/user/development/anaconda3/bin/python: No module named /home/user/development/rst-citations-to-raw-latex/RSTCitations
However the path is correct. That is exactly where the code is.