python需要设置哪些环境变量?我只知道一个PYTHONHOME指向安装目录。

如题所述

1、首先,右键点击-计算机(此电脑),点击进入属性,如图所示。

2、进入系统熟悉后,在点击进入-高级系统设置,如图所示。

3、在系统属性中,单击-环境变量-按钮,如图所示。

4、在环境变量页面中,点击“Administrator的用户变量”下面的-新建,如图所示。

5、在新建用户变量中,设置变量名:Path  变量值C:\Python\Python27;C:\Python\Python27\Scripts;如图所示版本不同手动更改,如:C:\Python\Python37;C:\Python\Python37\Scripts。

6、点击确定后,环境变量中即会出现新的用户变量,接着再次点击确定,即可设置完成,如图所示。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-12-25
1. 一般系统(Windows/Linux/....)Python被安装后解释器启动(例如python, python3 等命令)都可以自己找到"家"的, 不要设这个环境变量, 这个家就是解释本身附带的模块库或者将来安装其他的Python模块库的路径起始点.
如果你设了这个变量, 那么解释器的"家", 就被覆盖了, 然后不信你试试(保证PYTHONHOME设的目录存在), 设好这个环境变量以后, 然后运行如下命令: 1. python 基本马上提示:
ImportError: No module named site 他找不到家了

2. PYTHONHOME 一般是自己在指定位置给python安了新家, 不同于系统安装的目录位置, 一般为了安装一个特定版本python发布, 而不伤害到系统本身的安装, 才设这个变量, 同样你如果要安装工作在这个版本上的其他Python程序同样要指定这个变量!
第2个回答  2019-03-01
就这个问题而言,需要将PYTHONHOME添加到环境变量。否则在Python与C++等混合编程的时候会遇到问题。当然,如果没添加的话,在代码中也可以用C++函数:Py_SetPythonHome来代替,但是后者是临时的,必须每次都设置。
第3个回答  2011-12-31
直接安装的不需要设置。
第4个回答  2011-12-30
正常来说应该是可以什么都不用设置的,比如说你说的PYTHONHOME,这个不是需要你设置来指定一个目录的,而是当你需要修改默认目录的时候才应该修改这个环境变量,具体可以参考官方文档:

PYTHONHOME
Change the location of the standard Python libraries. By default, the libraries are searched in prefix/lib/pythonversion and exec_prefix/lib/pythonversion, where prefix and exec_prefix are installation-dependent directories, both defaulting to /usr/local.

When PYTHONHOME is set to a single directory, its value replaces both prefix and exec_prefix. To specify different values for these, set PYTHONHOME to prefix:exec_prefix.

PYTHONPATH
Augment the default search path for module files. The format is the same as the shell’s PATH: one or more directory pathnames separated by os.pathsep (e.g. colons on Unix or semicolons on Windows). Non-existent directories are silently ignored.

In addition to normal directories, individual PYTHONPATH 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 (see PYTHONHOME above). It is always appended to PYTHONPATH.

An additional directory will be inserted in the search path in front of PYTHONPATH as described above under Interface options. The search path can be manipulated from within a Python program as the variable sys.path.

PYTHONSTARTUP
If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed in the same namespace where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session. You can also change the prompts sys.ps1 and sys.ps2 in this file.
PYTHONY2K
Set this to a non-empty string to cause the time module to require dates specified as strings to include 4-digit years, otherwise 2-digit years are converted based on rules described in the time module documentation.
PYTHONOPTIMIZE
If this is set to a non-empty string it is equivalent to specifying the -O option. If set to an integer, it is equivalent to specifying -O multiple times.
PYTHONDEBUG
If this is set to a non-empty string it is equivalent to specifying the -d option. If set to an integer, it is equivalent to specifying -d multiple times.
PYTHONINSPECT
If this is set to a non-empty string it is equivalent to specifying the -i option.

This variable can also be modified by Python code using os.environ to force inspect mode on program termination.

PYTHONUNBUFFERED
If this is set to a non-empty string it is equivalent to specifying the -u option.
PYTHONVERBOSE
If this is set to a non-empty string it is equivalent to specifying the -v option. If set to an integer, it is equivalent to specifying -v multiple times.
PYTHONCASEOK
If this is set, Python ignores case in import statements. This only works on Windows.
PYTHONDONTWRITEBYTECODE
If this is set, Python won’t try to write .pyc or .pyo files on the import of source modules.

New in version 2.6.

PYTHONIOENCODING
Overrides the encoding used for stdin/stdout/stderr, in the syntax encodingname:errorhandler. The :errorhandler part is optional and has the same meaning as in str.encode().

New in version 2.6.

PYTHONNOUSERSITE
If this is set, Python won’t add the user site-packages directory to sys.path.

New in version 2.6.

See also PEP 370 – Per user site-packages directory
PYTHONUSERBASE
Defines the user base directory, which is used to compute the path of the user site-packages directory and Distutils installation paths for python setup.py install --user.

New in version 2.6.

See also PEP 370 – Per user site-packages directory
PYTHONEXECUTABLE
If this environment variable is set, sys.argv[0] will be set to its value instead of the value got through the C runtime. Only works on Mac OS X.
PYTHONWARNINGS
This is equivalent to the -W option. If set to a comma separated string, it is equivalent to specifying -W multiple times.
1.2.1. Debug-mode variables
Setting these variables only has an effect in a debug build of Python, that is, if Python was configured with the --with-pydebug build option.

PYTHONTHREADDEBUG
If set, Python will print threading debug info.

Changed in version 2.6: Previously, this variable was called THREADDEBUG.

PYTHONDUMPREFS
If set, Python will dump objects and reference counts still alive after shutting down the interpreter.
PYTHONMALLOCSTATS
If set, Python will print memory allocation statistics every time a new object arena is created, and on shutdown.本回答被提问者采纳
相似回答