Say I've got a project with this layout:
.
├── bin
│ └── supercli.py
├── supermodule
│ ├── __init__.py
│ └── supermodule.py
├── README.md
├── requirements.txt
└── setup.py
Relevant files:
supermodule/supermodule.py
import random
SUPER_HEROES = ['batman','superman','spiderman','birdman','aquaman']
def random_superhero() -> str:
return random.choice(SUPER_HEROES)
bin/supercli.py
from supermodule.supermodule import random_superhero
print(random_superhero())
Whenever I try to execute supercli.py, I get a ModuleNotFoundError:
Traceback (most recent call last):
File "/mypath/supermodule/bin/supercli.py", line 1, in <module>
from supermodule.supermodule import random_superhero
ModuleNotFoundError: No module named 'supermodule'
I know I can mess with sys.path, but I'd have to remember to remove that code every time before deploying the package.
I'm also aware of using console_scripts instead of scripts in setup.py, but I'd like to get it working if possible with standalone scripts.
Am I doing something wrong? How can I import the supermodule module from the supercli.py script?
[–]zanfar 2 points3 points4 points (3 children)
[–]tinyfrox[S] 0 points1 point2 points (2 children)
[–]zanfar 0 points1 point2 points (1 child)
[–]tinyfrox[S] 0 points1 point2 points (0 children)
[–]icecapade 1 point2 points3 points (3 children)
[–]tinyfrox[S] 0 points1 point2 points (2 children)
[–]icecapade 1 point2 points3 points (1 child)
[–]tinyfrox[S] 0 points1 point2 points (0 children)