Python Importing Works From One Folder But Not Another
I have a project directory that is set up in the following way: >root > modules __init__.py module1.py > moduleClass __init__.py
Solution 1:
When you run a script, Python adds the script's containing directory (here, scripts/
) to sys.path
. If your modules don't appear in sys.path
any other way, that means Python may not be able to find them at all.
The usual solution is to put your scripts somewhere in your module hierarchy and "run" them with python -m path.to.module
. But in this case, you could just use an existing test runner: Python comes with python -m unittest discover
, or you might appreciate something fancier like py.test (pip install --user pytest
).
Post a Comment for "Python Importing Works From One Folder But Not Another"