Fork me on GitHub

Python系列文章-Python中的环境变量介绍

目录

  • 背景

  • 第一部分 变量说明

  • 第二部分 总结

  • 参考文献及资料

背景

环境说明:Python 3.7.3

使用下面的命令显示相关版本的说明信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# python --help
# ......
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH : ':'-separated list of directories prefixed to the
default module search path. The result is sys.path.
PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).
The default module search path uses <prefix>/lib/pythonX.X.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.
PYTHONHASHSEED: if this variable is set to 'random', a random value is used
to seed the hashes of str, bytes and datetime objects. It can also be
set to an integer in the range [0,4294967295] to get hash values with a
predictable seed.
PYTHONMALLOC: set the Python memory allocators and/or install debug hooks
on Python memory allocators. Use PYTHONMALLOC=debug to install debug
hooks.
PYTHONCOERCECLOCALE: if this variable is set to 0, it disables the locale
coercion behavior. Use PYTHONCOERCECLOCALE=warn to request display of
locale coercion and locale compatibility warnings on stderr.
PYTHONBREAKPOINT: if this variable is set to 0, it disables the default
debugger. It can be set to the callable of your debugger of choice.
PYTHONDEVMODE: enable the development mode.

第一部分 变量说明

1.1 PYTHONSTARTUP

就是一个运行交互式解释器之前会自动调用的一个文件,我们可以在这个文件中放入一些我们想再解释器中事先运行的一些代码,比如导入一些经常会用到的一些模块等等。这个文件是在系统变量中用PYTHONSTARTUP指向的文件。就是在打开一个解释器之前要做的事情。

1.2 PYTHONPATH

The PYTHONPATH variable has a value that is a string with a list of directories that Python should add to the sys.path directory list.

增加模块文件默认搜索路径。 所用格式与终端的 PATH 相同:一个或多个由 os.pathsep 分隔的目录路径名称(例如 Unix 上用冒号而在 Windows 上用分号)。 默认忽略不存在的目录。

1.3 PYTHONHOME

第二部分 总结

对于zip包文件支持

从 Python 2.3 开始,您可以从ZIP 文件中导入模块和包。此功能称为Zip 导入

参考文献及资料

1、变量官网介绍:https://docs.python.org/zh-cn/3/using/cmdline.html#environment-variables

0%