Here is my directory structure:
NEW3 has 2 sub directories:
NEW1
NEW2
NEW1 - has test1.py
NEW2 - has test2.py
How to import test2.py
in test1.py
?
Here is my directory structure:
NEW3 has 2 sub directories:
NEW1
NEW2
NEW1 - has test1.py
NEW2 - has test2.py
How to import test2.py
in test1.py
?
Add NEW3
to python path, create empty __init__.py
in each directory, then you can add this line in test1.py:
from NEWS3.NEWS2 import test2
To add a directory to python path you can simply add export PYTHONPATH="${PYTHONPATH}:/my/other/path"
in .bashrc
.
There is a way to do it with python, create a file mymodule.pth
in python dist-packages
path (/usr/lib/python2.7/dist-packages
) and add one line containing the directory to add to python path
.
Put a "init.py" file in the NEW2 DIR, an empty file is fine. Then you can use "..".
import sys
sys.path.append("..")
import NEW2.test2