Python: PythonHOME和PYTHONPATH的區(qū)別
Python: PYTHONhome和PYTHONPATH的區(qū)別
目錄
PYTHONhome和PYTHONPATH的區(qū)別
6.1.2.?The Module Search Path
sys.path
PYTHONHOME和PYTHONPATH的區(qū)別
官方文檔解讀:https://docs.python.org/3/tutorial/modules.html
6.1.2.?The Module Search Path
When a module named?spam?is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named?spam.py?in a list of directories given by the variable?sys.path.?sys.path?is initialized from these locations:
The directory containing the input script (or the current directory when no file is specified).
PYTHONPATH?(a list of directory names, with the same syntax as the shell variable?PATH).
The installation-dependent default.
當導入名為spam的模塊時,解釋器首先搜索具有該名稱的內(nèi)置模塊。如果沒有找到,它會搜索一個名為spam.py的文件。變量sys.path. sys給出的目錄列表中的py。路徑是從這些位置初始化的:
包含輸入腳本的目錄(或未指定文件時的當前目錄)。
PYTHONPATH(一個目錄名列表,與shell變量PATH具有相同的語法)。
installation-dependent默認。
Note:On file systems which support symlinks, the directory containing the input script is calculated after the symlink is followed. In other words the directory containing the symlink is?not?added to the module search path.
After initialization, Python programs can modify?sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section?Standard Modules?for more information.
sys.path
sys.path 包含輸入模塊的目錄名列表,并且當前目錄也是sys.path的一部分。
Python
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。