Situation:
Given this project structure:
project/
app/
__init__.py (empty)
stamp.py
tests/
test.py
main.py
In main.py and test.py I am trying to import the functionality of stamp.py via:
from app.stamp import Timestamp
Timestamp gets imported in main.py but not in test.py where I get this error:
ImportError: No module named 'app'
Question:
How can I in python 3.5 import functionality of stamp.py in test.py?
make sure your folder tests contains __init__.py
Below code appends the path of your project project to sys.path in test.py
python will go through to search the modules and files in your project
import sys
sys.path.append("/path/to/project")
from app.stamp import Timestamp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With