将Python添加到Windows环境变量

2024-04-25 14:46:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python已经有一段时间了,但是我一直无法从Windows命令行正确地运行它。显示的错误是:

C:\Windows\system32>python

'python' is not recognized as an internal or external command, operable program or batch file.

我已经试着解决这个问题很多次了。我知道这是一个编辑环境变量的问题,但这并没有解决问题。我的系统路径变量当前为

C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk

这是Python在我的目录中的正确位置。我已经尝试将此添加到我的用户路径中,并尝试创建一个包含它们的PYTHONPATH变量。在

我应该注意到跑步python.exe有效果。在

C:\Windows\system32>python.exe

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information.

我试过各种各样的解决办法都没有用。非常感谢任何帮助。在


Tags: or命令行路径aniswindowslibas
1条回答
网友
1楼 · 发布于 2024-04-25 14:46:08

安装python3.3或更高版本。它附带了一个名为Python启动器的实用程序(py.exe文件),它安装在Windows目录中,并且已经在路径中。有了它,您可以启动已经安装的任何版本的Python。在

可以用PY_PYTHON变量覆盖要运行的默认Python。在

下面是一个演示。我安装了三个版本的Python:

C:\>set PY_PYTHON
PY_PYTHON=3.3

C:\>py
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

C:\>py -2
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

C:\>py -3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

另外,如果在Python文件的顶部添加一行特殊的行,则可以选择脚本将在哪个版本的Python下运行:

^{pr2}$

完整详细信息:https://docs.python.org/3.4/using/windows.html#python-launcher-for-windows

相关问题 更多 >