@contribute
2016-09-08T08:19:04.000000Z
字数 960
阅读 1158
python
假设一个名为spam
的模块被导入。
则python解释器的搜索路径:interpreter首先从built-in模块中搜索其名字spam
。如果没有找到,则在sys.path
中查找。而sys.path
由以下位置初始化:
可以在python 环境下使用
sys.path.append(path)
添加相关的路径,但在退出python环境后自己添加的路径就会自动消失!
Augment the default search path for module files. The format is the same as the shell’sPATH
: one or more directory pathnames separated byos.pathsep
(e.g. colons on Unix or semicolons on Windows). Non-existent directories are silently ignored.
In addition to normal directories, individualPYTHONPATH
entries may refer to zipfiles containing pure Python modules (in either source or compiled form). Extension modules cannot be imported from zipfiles.
The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (seePYTHONHOME
above). It is always appended toPYTHONPATH
.
An additional directory will be inserted in the search path in front ofPYTHONPATH
as described above under Interface options. The search path can be manipulated from within a Python program as the variable sys.path.