Add module search path
Dynamically add directories
import sys sys.path.append("the directory of module")
This method only works on modules that contain the above statement.
Modify the PYTHONPATH variable
under windows: create a
new PYTHONPATH environment variable, and then append the path where the python module is located to the variable.
Under linux:export PYTHONPATH=$PYTHONPATH:/home/wang/workspace $ source ~/.bashrc # 或者 . ~/.bashrc
This method is permanently added to the python search path.
Add a .pth
file Add a configuration file (eg: extras.pth) with the extension of .pth under [Directories already in the search path], and the content is the path to be added.
This method is also added permanently.