import file_name as fn
or
from file_name import *
The file_name
above is the name of your specific .py file under the same folder of your script.
from file_path.file_name import *
We link the file_path
with file_name
using .
rather than /
.
import sys
module_path = '/absolute/path/in/system'
sys.path.append(module_path)
from file_name import *
We can import sys
at first, then add file path to system path environment in python.
However, we can simplify this process by adding your module path to environment permamentally
$ export PYTHONPATH=$PYTHONPATH:/absolute/path/in/system
$ python -c "import sys; print(sys.path)
The first line add your path to environment, and the second line check the path in your environment. After this, you may just import your package with only one line at beginning.
from file_path.file_name import *