How do I add a path "permanent" to Sys.path?
Sys.path is the path set of the Python search module and is a list
You can use Sys.path.append (path) to add related paths in a Python environment, but the paths you add automatically disappear when you exit the Python environment!
You can use the following command to enter the search path for the current Python:
Python-c "Import Sys;print" current Python is: ' +sys.prefix;print ' \ n '. Join (Sys.path) "
Practice using the Sys.path.append method to add a path that shows that exiting Python will disappear!
Python-c "Import Sys;print" current Python is: ' +sys.prefix; sys.path.append (R ' E:\DjangoWord ');p rint ' \ n '. Join (Sys.path) "
Run again and you will find yourself adding the path E:\DjangoWord () does not exist!
Python-c "Import Sys;print" current Python is: ' +sys.prefix;print ' \ n '. Join (Sys.path) "
To solve this problem, the following methods can be used:
Place your own py file in the Site_packages directory:
The following command shows the Site-packages directory:
Python-c "fromdistutils.sysconfig import get_python_lib; Print get_python_lib ()"
However, this can lead to a problem, that is, the various types of modules placed in this folder, will lead to a disorderly problem, this is obvious.
Note that you do not create subfolders, and then place your own modules in subfolders to resolve the issue, which results in an error when using the import statement.
Using the PTH file, create the. pth file in the Site-packages file, write the path to the module, one line at a path, the following is an example, the PTH file can also use annotations:
#. pth file for the My project (this line is a comment)
E:\DjangoWord
E:\DjangoWord\mysite
E:\DjangoWord\mysite\polls
This is a good approach, but there are administrative issues and cannot be shared in different versions of Python.
I'm using the 2nd method.
Python imports templates for other catalogs