Python: PYTHONHOME和PYTHONPATH的区别

网友投稿 1167 2022-05-30

Python: PYTHONhome和PYTHONPATH的区别

目录

PYTHONHOME和PYTHONPATH的区别

6.1.2. The Module Search Path

sys.path

PYTHONHOME和PYTHONPATH的区别

官方文档解读: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的模块时,解释器首先搜索具有该名称的内置模块。如果没有找到,它会搜索一个名为spam.py的文件。变量sys.path. sys给出的目录列表中的py。路径是从这些位置初始化的:

包含输入脚本的目录(或未指定文件时的当前目录)。

Python: PYTHONHOME和PYTHONPATH的区别

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:DevOps进阶(十二)GIT、GITLAB、GITHUB、GITLIB
下一篇:用华为云Ubuntu搭建LAMP环境
相关文章