In general, we will write our own Python module and Python's own modules stored separately to achieve easy maintenance purposes.
The Python runtime environment is a sys.path list when looking for a module, and if we want to add a custom module to the runtime, there are three main ways to do this:
1. Add a new path to the Sys.path list (only works for the current Python runtime that executes the Sys.path.append command, which does not work for the other runtime, i.e. "disposable").
>>> Import sys
>>> Sys.path
>>> sys.path.append ('/home/xxx/yyy ') #目录 /home/xxx/yyy contains the packages or modules you need
Set the PYTHONPATH environment variable (permanently added):
2. Copy the package or module to a directory in the Sys.path list (Sys.path view) (such as the/home/test/lib/python2.7/site-packages/directory).
3. the simplest approach is to use the. pth file to implement. as Python iterates through the existing library file directory (specified in Sys.path), if a. pth file is seen, the path that is recorded in the file is added to the Sys.path setting so that the. pth file says that the specified library can be found in the Python runtime environment.
$CD /home/test/lib/python2.7/site-packages/
$touch test.pth
$vim test.pth
$ Add a single line of packages or modules in the same directory (for example:/home/test/somepackage/)
the contents of the Test.pth file are:
/home/test/somepackage/
Python import custom Packages or modules