How do you append directories to your Python path?
Your path (i.e. the list of directories Python goes through to
search for modules and files) is stored in the path
attribute of the sys
module. Since path
is a list, you can use the append
method to add
new directories to the path.
For instance, to add the directory /home/me/mypy
to
the path, just do:
import sys
sys.path.append("/home/me/mypy")
Greg Ward's Installing Python Modules document has more information on other ways of modifying the search path.
Advertisement: In 2012, I published the book A Hands-On Introduction to Using Python in the Atmospheric and Oceanic Sciences. If you're new to Python, you may find it useful!