PYTHONPATH
- The PYTHONPATH variable can be set to a list of paths that will be added to the beginning of sys.path
- export PYTHONPATH="/User/lchen/.local/python:$PYTHONPATH", set environment variable PYTHONPATH in .bash_profile or .profile under $HOME directory
sys.path
import sys
sys.path.insert(0,'/path/to/mod_directory')
# or
sys.path.append(mod_directory)
Python configuration file
- python -m site --user-site, first find out in which directory Python searches for path configuration file
- Create .pth file under this directory, add the path in the file
#/Users/lchen/.local/lib/python2.7/site-packages
#Create temp.pth file under the directory
/Users/lchen # add this path to the path configuration file
#Add m.py under /User/lchen
import m