如何在 Windows 7 的命令提示符下运行 Python 程序?
我正在尝试弄清楚如何在 Windows 7 上使用命令提示符运行 Python 程序。(我现在应该已经弄清楚了......)
当我在命令提示符中键入“python”时,出现以下错误:
“python”未被识别为内部或外部命令, 可运行的程序或批处理文件。
我在寻求帮助时发现的第一个地方是这个网站: http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows。
它有点帮助,但该教程是为 Windows 2000 及更早版本编写的,因此它对我的 Windows 7 计算机几乎没有帮助。我尝试了以下操作:
对于旧版本的 Windows,最简单的方法是编辑 C:\AUTOEXEC.BAT > 文件。您需要向 AUTOEXEC.BAT 添加如下行:
此文件在我的计算机上不存在(除非我弄错了)。
接下来,我尝试了这个:(此处:如何运行Python程序?< /a>)
将 Python 放入您的路径中
窗口
为了运行程序,您的操作系统会查找各个位置,并尝试将您键入的程序/命令的名称与一路上的某些程序相匹配。
在窗口中:
控制面板>系统>高级> |环境变量| >系统变量->路径
这需要包括:C:\Python26; (或同等内容)。如果你把它放在前面,它将是第一个看到的地方。您也可以将其添加在末尾,这可能更明智。
然后重新启动提示符,并尝试输入“python”。如果一切正常,您应该会看到“>>”提示。
这对于 Windows 7 来说足够相关了,我进入了系统变量。我添加了一个值为“C:\Python27”的变量“python”,
即使重新启动计算机后,我仍然收到错误。
有人知道如何解决这个问题吗?
I'm trying to figure out how to run Python programs with the Command Prompt on Windows 7. (I should have figured this out by now...)
When I typed "python" into the command prompt, I got the following error:
'python' is not recognized as an internal or external command,
operable program or batch file.
The first place I found when looking for help was this site: http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows.
It was somewhat helpful, but the tutorial was written for Windows 2000 and older, so it was minimally helpful for my Windows 7 machine. I attempted the following:
For older versions of Windows the easiest way to do this is to edit the C:\AUTOEXEC.BAT >file. You would want to add a line like the following to AUTOEXEC.BAT:
This file did not exist on my machine (unless I'm mistaken).
Next, I tried this: (here: How do I run a Python program?)
Putting Python In Your Path
Windows
In order to run programs, your operating system looks in various places, and tries to match the name of the program / command you typed with some programs along the way.
In windows:
control panel > system > advanced > |Environmental Variables| > system variables -> Path
this needs to include: C:\Python26; (or equivalent). If you put it at the front, it will be the first place looked. You can also add it at the end, which is possibly saner.
Then restart your prompt, and try typing 'python'. If it all worked, you should get a ">>>" prompt.
This was relevant enough for Windows 7, and I made my way to the System Variables. I added a variable "python" with the value "C:\Python27"
I continued to get the error, even after restarting my computer.
Anyone know how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(24)
您需要将
C:\Python27
添加到系统 PATH 变量,而不是名为“python”的新变量。找到系统PATH环境变量,并在其后面附加一个
;
(这是分隔符)和包含python.exe的目录的路径(例如C:\Python27
) 。具体步骤请参见下文。PATH 环境变量列出了 Windows(和
cmd.exe
)在给定命令名称(例如“python”)时将检查的所有位置(它还使用 PATHEXT 变量作为可执行文件列表)尝试扩展)。它在 PATH 上找到的第一个具有该名称的可执行文件就是它启动的文件。请注意,更改此变量后,无需重新启动 Windows,但只有
cmd.exe
的新实例才会具有更新的 PATH。您可以在命令提示符下键入set PATH
来查看当前值是什么。在 Windows 7+ 上将 Python 添加到路径的确切步骤:
环境变量...
按钮(在“高级”选项卡中);C:\Python27
添加到末尾(替换您的 Python 版本)You need to add
C:\Python27
to your system PATH variable, not a new variable named "python".Find the system PATH environment variable, and append to it a
;
(which is the delimiter) and the path to the directory containing python.exe (e.g.C:\Python27
). See below for exact steps.The PATH environment variable lists all the locations that Windows (and
cmd.exe
) will check when given the name of a command, e.g. "python" (it also uses the PATHEXT variable for a list of executable file extensions to try). The first executable file it finds on the PATH with that name is the one it starts.Note that after changing this variable, there is no need to restart Windows, but only new instances of
cmd.exe
will have the updated PATH. You can typeset PATH
at the command prompt to see what the current value is.Exact steps for adding Python to the path on Windows 7+:
Environment variables...
button (in the Advanced tab);C:\Python27
to the end (substitute your Python version)假设您安装了Python2.7
转到开始菜单
右键单击“计算机”
选择“属性”
将弹出一个对话框,左侧有一个名为“高级系统设置”的链接。单击它。
在“系统属性”对话框中,单击“环境变量”按钮。
在“环境变量”对话框中,在“系统变量”窗口下查找“Path”。
将“;C:\Python27”添加到其末尾。分号是 Windows 上的路径分隔符。
单击“确定”并关闭对话框。
现在打开一个新的命令提示符并输入“python”
它应该可以工作。
Assuming you have Python2.7 installed
Goto the Start Menu
Right Click "Computer"
Select "Properties"
A dialog should pop up with a link on the left called "Advanced system settings". Click it.
In the System Properties dialog, click the button called "Environment Variables".
In the Environment Variables dialog look for "Path" under the System Variables window.
Add ";C:\Python27" to the end of it. The semicolon is the path separator on windows.
Click Ok and close the dialogs.
Now open up a new command prompt and type "python"
It should work.
我花了一些功夫在这里、在网络上、在 Python 文档中寻找答案,并自己进行测试,最终让我的 Python 脚本在我的 Windows 机器(WinXP 和 Win7)上顺利运行。所以,我刚刚在博客上介绍了它,并将其粘贴在下面,以防对其他人有用。抱歉有点长,欢迎大家改进;我不是专家。
[更新:Python 3.3 现在包含适用于 Windows 的 Python 启动器,它允许您键入 py(而不是 python)来调用默认解释器,或 py -2、py -3、py -2.7、等等。它还支持shebang行,允许脚本本身指定。对于 3.3 之前的版本,启动器可单独下载。
http://docs.python.org/3/whatsnew/3.3.html
]
在 Windows 下方便地运行 Python 脚本
也许您正在创建自己的 Python 脚本,或者可能有人为您提供了一个用于处理数据文件的脚本。假设您已经获取了一个 Python 脚本并将其保存到“D:\my scripts\ApplyRE.py”。您希望通过双击它或从任何位置将其键入命令行来方便地运行它,并可以选择向其传递参数,如下所示(-o 表示“如果输出文件已存在,则覆盖它”)
:您还有一个数据文件“C:\some files\some lexicon.txt”。最简单的选择是移动文件或脚本,使它们位于同一位置,但这可能会变得混乱,所以我们假设它们将保持独立。
确保 Windows 可以找到 Python 解释器
安装 Python 后,验证在命令提示符中键入 python 是否有效(然后键入 exit() 以退出 Python 解释器)。
如果这不起作用,您需要将类似“;C:\Python32”(不带引号)的内容附加到 PATH 环境变量中。请参阅下面的 PATHEXT 以获取说明。
将 Python 与 .py 和 .pyc 关联起来
验证双击 ApplyRE.py 是否会运行它。 (顺便说一句,它还应该有一个 Python 徽标作为其图标,并标记为“Python 文件”。)如果尚未完成此操作,请右键单击 .py 文件,选择“打开方式”,选择“程序”,然后选中“始终使用...”这种关联提高了便利性,但并不是绝对必要的 - 您可以每次想要运行脚本时指定“python”,如下所示:
这是一个非常具体的变体,除非您需要,否则它是可选的指定不同版本的解释器。
但这很痛苦。幸运的是,一旦 Python 安装在 PATH 中并与 .py 关联,那么双击 .py 文件或直接将其作为命令键入应该可以正常工作。在这里,我们似乎直接运行脚本——在与脚本一起位于“我的脚本”文件夹中的示例文件上运行它是很好而且简单的。
省略 .py 扩展名(编辑 PATHEXT)
为了进一步减少输入,您可以告诉 Windows .py(也许还有 .pyc 文件)是可执行的。为此,右键单击“计算机”,然后选择“属性”、“高级”、“环境变量”、“系统变量”。将“;.PY;.PYC”(不带引号)附加到现有的 PATHEXT 变量,或者如果您确定它尚不存在,则创建它。关闭并重新打开命令提示符。您现在应该能够省略 .py(仅供参考,这样做会导致 ApplyRE.exe 或 ApplyRE.bat 运行,如果存在的话)。
将脚本添加到系统 PATH
如果您要经常从命令提示符使用脚本(如果通过使用 BAT 文件这样做则不太重要),那么您需要将脚本文件夹添加到系统 PATH。 (在 PATHEXT 旁边,您应该看到一个 PATH 变量;将“;D:\my script”附加到它,不带引号。)这样您就可以从其他位置针对当前位置的文件运行脚本,如下所示:
成功!这几乎就是简化命令行所需要做的全部事情。
直接运行而不调整 PATH
如果您是一个快速打字员或者不介意为每种情况创建一个批处理文件,您可以指定完整路径(对于脚本或参数)而不是调整 PATH。
创建快捷方式或批处理文件
如果 .py 与已安装的 Python 关联,您只需双击 ApplyRE.py 即可运行它,但控制台可能出现和消失得太快而无法读取其输出(或失败!)。要传递参数,您需要首先执行以下操作之一。
(a) 右键单击并创建快捷方式。右键单击快捷方式以编辑属性并将参数附加到目标。
(b) 创建一个批处理文件——具有不同名称的纯文本文件,例如ApplyRErun.bat。此选项可能更好,因为您可以要求它暂停,以便您可以看到输出。以下是示例 BAT 文件的内容,编写为从 c:\some files 定位并运行。
高级:附加到 PYTHONPATH
这通常不是必需的,但另一个可能相关的环境变量是 PYTHONPATH。如果我们将 d:\my 脚本附加到该变量,那么其他位置的其他 Python 脚本可以通过 import 语句使用这些脚本。
It has taken me some effort looking for answers here, on the web, and and in the Python documentation, and testing on my own, to finally get my Python scripts working smoothly on my Windows machines (WinXP and Win7). So, I just blogged about it and am pasting that below in case it's useful to others. Sorry it's long, and feel free to improve it; I'm no expert.
[UPDATE: Python 3.3 now includes the Python Launcher for Windows, which allows you to type py (rather than python) to invoke the default interpreter, or py -2, py -3, py -2.7, etc. It also supports shebang lines, allowing the script itself to specify. For versions prior to 3.3, the launcher is available as a separate download.
http://docs.python.org/3/whatsnew/3.3.html
]
Running Python scripts conveniently under Windows
Maybe you're creating your own Python scripts, or maybe someone has given you one for doing something with your data files. Say you've acquired a Python script and have saved it to "D:\my scripts\ApplyRE.py". You want to run it conveniently by either double-clicking it or typing it into the command line from any location, with the option of passing parameters to it like this (-o means "overwrite the output file if it already exists"):
Say you also have a data file, "C:\some files\some lexicon.txt". The simplest option is to move the file or the script so they're in the same location, but that can get messy, so let's assume that they'll stay separate.
Making sure Windows can find the Python interpreter
After installing Python, verify that typing python into a command prompt works (and then type exit() to get back out of the Python interpreter).
If this doesn't work, you'll need to append something like ";C:\Python32" (without quotes) to the PATH environment variable. See PATHEXT below for instructions.
Associating Python with .py and .pyc
Verify that double-clicking on ApplyRE.py runs it. (It should also have a Python logo as its icon and be labeled "Python File", by the way.) If this isn't already done, right-click on a .py file, choose Open With, Choose Program, and check "Always use..." This association improves convenience but isn't strictly necessary--you can specify "python" every time you want to run a script, like this:
Here's a very specific variation, which is optional unless you need to specify a different version of the interpreter.
But that's a pain. Fortunately, once Python is installed, in the PATH, and associated with .py, then double-clicking a .py file or directly typing it as a command should work fine. Here, we seem to be running the script directly--it's nice and simple to run it on a sample file that's located in the "my scripts" folder along with the script.
Omitting the .py extension (editing PATHEXT)
To further reduce typing, you can tell Windows that .py (and perhaps .pyc files) are executable. To do this, right-click Computer and choose Properties, Advanced, Environment Variables, System Variables. Append ";.PY;.PYC" (without quotes) to the existing PATHEXT variable, or else create it if you're certan it doesn't exist yet. Close and reopen the command prompt. You should now be able to omit the .py (FYI, doing so would cause ApplyRE.exe or ApplyRE.bat to run instead, if one existed).
Adding scripts to the system PATH
If you're going to use your scripts often from the command prompt (it's less important if doing so via using BAT files), then you'll want to add your scripts' folder to the system PATH. (Next to PATHEXT you should see a PATH variable; append ";D:\my scripts" to it, without quotes.) This way you can run a script from some other location against the files in current location, like this:
Success! That's pretty much all you need to do to streamline the command-line.
Running directly without tweaking the PATH
If you're a fast typist or don't mind creating a batch file for each situation, you can specify full paths (for the script, or for the parameters) instead of tweaking PATH.
Creating shortcuts or batch files
If .py is associated with an installed Python, you can just double-click ApplyRE.py to run it, but the console may appear and disappear too quickly to read its output (or failure!). And to pass parameters, you'd need to first do one of the following.
(a) Right-click and create a shortcut. Right-click the shortcut to edit properties and append parameters to Target.
(b) Create a batch file--a plain text file with a distinct name such as ApplyRErun.bat. This option is probably better because you can ask it to pause so you can see the output. Here is a sample BAT file's contents, written to be located and run from c:\some files .
Advanced: appending to PYTHONPATH
This usually isn't necessary, but one other environment variable that may be relevant is PYTHONPATH. If we were to append d:\my scripts to that variable, then other Python scripts in other locations could make use of those via import statements.
Python 附带了一个脚本,负责为您设置 Windows 路径文件。
安装完成后,打开命令提示符
cmd
进入你安装 Python 的目录
cd C:\Python27
运行 python 以及 Tools\Scripts 中的 win_add2path.py 脚本
python .exe Tools\Scripts\win_add2path.py
现在您可以在任何地方使用
python
作为命令。Python comes with a script that takes care of setting up the windows path file for you.
After installation, open command prompt
cmd
Go to the directory you installed Python in
cd C:\Python27
Run python and the win_add2path.py script in Tools\Scripts
python.exe Tools\Scripts\win_add2path.py
Now you can use
python
as a command anywhere.您必须将 python 路径放入 PATH 变量中。
在系统变量部分,您应该有用户变量和系统变量。搜索
PATH
变量并编辑其值,在末尾添加;C:\python27
。;
是告诉变量向该值添加新路径,其余的只是告诉该路径是哪条路径。另一方面,您可以使用
;%python%
添加您创建的变量。You have to put the python path in the
PATH
variable.In the System Variables section, you should have User Variables and System Variables. Search for the
PATH
variable and edit its value, adding at the end;C:\python27
.The
;
is to tell the variable to add a new path to this value, and the rest, is just to tell which path that is.On the other hand, you can use
;%python%
to add the variable you created.即使浏览了很多帖子,还是花了几个小时才找出问题所在。以下是用简单语言编写的在 Windows 中通过命令行运行 python 的详细方法。
1.从 python.org
下载可执行文件
选择最新版本并下载 Windows 可执行安装程序。执行下载的文件并完成安装。
2.确保文件下载到某个管理员文件夹中
如果否,您可以跳到步骤 3。否则,将 Python37 或您下载的任何版本克隆到以下位置之一:“C:\”、“C:\Program Files”、“C:\Program Files” (x86)”。
<强>3。更新系统PATH变量
这是最关键的一步,有两种方法可以做到这一点:-
(最好遵循第二个)
1。手动
- 在搜索栏中搜索“编辑系统环境变量”。(WINDOWS 10)
- 在“系统属性”对话框中,导航至“环境变量”。
- 在“环境变量”对话框中,在“系统变量”窗口下查找“路径”。 (# 确保单击名为系统变量的底部窗口下的路径,而不是用户变量下的路径)
- 通过添加 Python37/PythonXX 文件夹的位置来编辑路径变量。我添加了以下行:-
" ;C:\Program Files (x86)\Python37;C:\Program Files (x86)\Python37\Scripts "
- 单击“确定”并关闭对话框。
2。脚本化
- 打开命令提示符并使用 cd 命令导航到 Python37/XX 文件夹。
- 写下以下语句:-
“python.exe Tools\Scripts\win_add2path.py”
您现在可以在命令提示符中使用 python :)
1.使用外壳
在cmd中输入python并使用它。
2.执行 .py 文件
输入 python filename.py 来执行它。
Even after going through many posts, it took several hours to figure out the problem. Here is the detailed approach written in simple language to run python via command line in windows.
1. Download executable file from python.org
Choose the latest version and download Windows-executable installer. Execute the downloaded file and let installation complete.
2. Ensure the file is downloaded in some administrator folder
If NO, you are good to go and jump to step 3. Otherwise, clone the Python37 or whatever version you downloaded to one of these locations, "C:\", "C:\Program Files", "C:\Program Files (x86)".
3. Update the system PATH variable
This is the most crucial step and there are two ways to do this:-
(Follow the second one preferably)
1. MANUALLY
- Search for 'Edit the system Environment Variables' in the search bar.(WINDOWS 10)
- In the System Properties dialog, navigate to "Environment Variables".
- In the Environment Variables dialog look for "Path" under the System Variables window. (# Ensure to click on Path under bottom window named System Variables and not under user variables)
- Edit the Path Variable by adding location of Python37/ PythonXX folder. I added following line:-
" ;C:\Program Files (x86)\Python37;C:\Program Files (x86)\Python37\Scripts "
- Click Ok and close the dialogs.
2. SCRIPTED
- Open the command prompt and navigate to Python37/XX folder using cd command.
- Write the following statement:-
"python.exe Tools\Scripts\win_add2path.py"
You can now use python in the command prompt:)
1. Using Shell
Type python in cmd and use it.
2. Executing a .py file
Type python filename.py to execute it.
您不向系统变量添加任何变量。您采用现有的“Path”系统变量,并通过在后面添加分号来修改它,然后添加 c:\Python27
You don't add any variables to the System Variables. You take the existing 'Path' system variable, and modify it by adding a semi-colon after, then c:\Python27
设置 PATH 后,
因此,经过 30 分钟的研发,我意识到在环境变量(即
“C:\Python/27;”)
只需重新启动
即可打开 cmd:
C:>; cd Python27
C:\Python27> python.exe
使用带扩展名的 python.exe
替代选项是:
如果软件安装正确,直接运行 Python 程序,您的命令行屏幕将自动出现,无需 cmd。
谢谢。
So after 30 min of R&D i realized that after setup the PATH at environment variable
i.e.
" C:\Python/27; "
just restart
now open cmd :
C:> cd Python27
C:\ Python27> python.exe
USE python.exe with extension
alternative option is :
if the software is installed properly directly run Python program, your command line screen will automatically appear without cmd.
Thanks.
转到开始菜单
右键单击“计算机”
选择“属性”
在“系统属性”对话框中,单击“环境变量”按钮。
在“环境变量”对话框中,在“系统变量”窗口下查找“Path”。
将“;C:\Python27”添加到其末尾。分号是 Windows 上的路径分隔符。
单击“确定”并关闭对话框。
现在打开一个新的命令提示符并输入“python”,或者如果它显示错误,请输入“py”而不是“python”
Go to the Start Menu
Right Click "Computer"
Select "Properties"
A dialog should pop up with a link on the left called "Advanced system settings". Click it.
In the System Properties dialog, click the button called "Environment Variables".
In the Environment Variables dialog look for "Path" under the System Variables window.
Add ";C:\Python27" to the end of it. The semicolon is the path separator on windows.
Click Ok and close the dialogs.
Now open up a new command prompt and type "python" or if it says error type "py" instead of "python"
只是想提一下,当您这样做时:
“管理员的用户变量”中的 PATH 变量已更改。
不过你也可以按照别人的回答打开:
系统->高级系统设置->高级->环境变量,
修改/添加“系统变量”中的变量Path,在其末尾添加
;C:\Python27
。Just want to mention, when you do:
The PATH variable in "user variables for administrator" is changed.
But you can also follow the others' answer to open:
System -> advanced system settings -> advanced -> Environment Variables,
and modify/add the variable Path in "System Variables", add
;C:\Python27
at the end of it.首先确保输入
path
环境变量First make sure you enter the
path
environment variable在 powershell 中输入以下内容:
关闭并打开 powershell,然后重试。这应该可以解决你的问题。
in powershell enter the following:
close and open the powershell and try again. this should solve your problem.
您需要编辑名为
PATH
的环境变量,并将;c:\python27
添加到其末尾。分号将一个路径名与另一个路径名分隔开(您的PATH
中已经有一些内容)。或者,您可以只
在命令提示符下键入,而无需修改任何环境变量。
You need to edit the environment variable named
PATH
, and add;c:\python27
to the end of that. The semicolon separates one pathname from another (you will already have several things in yourPATH
).Alternately, you can just type
at the command prompt without having to modify any environment variables at all.
在 Windows 上,您使用
C:\Python27\python.exe
而不是python
。如果将
C:\Python27
添加到路径中,则可以将其缩短为python.exe
,但您不需要这样做。On Windows you use
C:\Python27\python.exe
instead ofpython
.If you add
C:\Python27
to your path, you can shorten it to justpython.exe
, but you do not need to do this.也修改
PATH
变量并附加;%python%
否则无法找到可执行文件。Modify the
PATH
variable too and append;%python%
otherwise the executable can not be found.首先使用此 url 将 Python 安装到 Windows 中
然后添加路径变量为
First install the Python into your windows by using this url
and then add path variable as
在 Windows 7 中使用此路径:
Use this PATH in Windows 7:
即使我在环境变量中添加了路径,我也发现了同样的问题。最后,我将“C:\Python27”放在环境变量中“PATH”的前面部分,重新启动cmd后,它就可以工作了!
我希望这能有所帮助。
I also found the same problem even though i've added the path in the environment variable. Finally, I put my "C:\Python27" in the FRONT part of the "PATH" in environment variable and after restarting the cmd, it works!!!
I hope this can help.
对于 Windows 10 和 Windows 10 Python 3.5.1 用户:
在 Windows 10 上安装 Python 时,请不要忘记在点击“安装”之前检查“添加到 cmd 提示符”选项。这将有助于从 cmd 轻松访问 python。
如果未选中该选项,请使用 cmd 中的“设置路径”来查看它是否可作为可执行文件使用。如果没有,请导航至“开始”>>控制面板>>系统与安全>>系统>>高级系统设置>>高级>>环境变量.. >>>从系统变量中选择 PATH 并编辑它。然后将“C:\Python35\cmd”复制到新行中。此后,请以相同的过程将 .PY 添加到 PATHEXT。
另请检查是否开始>>控制面板>>系统与安全>>系统>>高级系统设置>>高级>>环境变量.. >>>用户变量来自用户名>> PATH 包含这两行 - "C:\Users\Username\AppData\Local\Programs\Python\Python35-32\Scripts\" & “C:\Users\用户名\AppData\Local\Programs\Python\Python35-32\”。否则请手动添加它们。
参考:https://docs.python.org/3/using/windows.html
For Windows 10 & Python 3.5.1 users:
While installing Python on Windows 10, please don't forget to check the "Add to cmd prompt" option before hitting the "Install". This would help in easily access python from cmd.
If the option was not checked, then please use Set Path in cmd to see if it is available as executables or not. If not, Navigate to Start >> Control Panel >> System and Security >> System >> Advanced System Settings >> Advanced >> Environment Variables.. >> Select PATH from System Variables and Edit it. Then copy "C:\Python35\cmd" in the new line. After this please add .PY to PATHEXT in the same procedure.
Also please check if Start >> Control Panel >> System and Security >> System >> Advanced System Settings >> Advanced >> Environment Variables.. >> User variables from Username >> PATH is containing these two lines - "C:\Users\Username\AppData\Local\Programs\Python\Python35-32\Scripts\" & "C:\Users\Username\AppData\Local\Programs\Python\Python35-32\". Else please add them manually.
Ref: https://docs.python.org/3/using/windows.html
转到开始菜单
右键单击“计算机”
选择“属性”
应弹出一个对话框,左侧有一个名为“高级系统设置”的链接。单击它。
在“系统属性”对话框中,单击“环境变量”按钮。
在“环境变量”对话框中,在“系统变量”窗口下查找“路径”。
将“;C:\Python27”添加到其末尾。分号是 Windows 上的路径分隔符。
单击“确定”并关闭对话框。
现在打开一个新的命令提示符并键入“python”
如果问题仍然存在,则在命令提示符中键入“py”而不是“python”。可能有帮助!
Goto the Start Menu
Right Click "Computer"
Select "Properties"
A dialog should pop up with a link on the left called "Advanced system settings". Click it.
In the System Properties dialog, click the button called "Environment Variables".
In the Environment Variables dialog look for "Path" under the System Variables window.
Add ";C:\Python27" to the end of it. The semicolon is the path separator on windows.
Click Ok and close the dialogs.
Now open up a new command prompt and type "python"
If still the problem persists then type "py" instead of "python" in command prompt. might help!!!!
按开始按钮,然后输入
cmd
。 - 请注意,您需要以“管理员”身份运行命令提示符。写入
setx -m path "%path%;C:\Python27"
然后按 Enter。[此处
-m
用于向所有用户授予访问权限,在Python27
27 中是版本 2.7]%path%;
将阻止原始值破坏。 C:\Python27 将附加到当前Path
值。就是这样,你就完成了。
press start button then type
cmd
. - Note you will need to run the command prompt as 'Adminstrator'.write
setx -m path "%path%;C:\Python27"
then press enter.[here
-m
for giving accessing permission to all users and inPython27
27 is version 2.7]%path%;
will prevent the original value from destroying. C:\Python27 will be appended to the currentPath
value.that's it,you are done.
您执行的所有步骤都是正确的,除了一个步骤,请尝试以下步骤,而不是创建一个单独的变量。
python.exe
文件,找到父文件夹。python
您必须看到版本详细信息All the steps you have performed are correct, except one step, instead creating one separate variable, try below steps.
python.exe
file, find the parent folder.python
you must see the version details转到安装 python 的路径(在开始菜单中输入 python 并打开文件位置)。在地址工具栏上,输入 Python 版本 - 对我来说是 Python 3.10(64 位),然后按 Enter。命令提示符将打开,并显示保存 python 的确切路径,以便代码可以运行。如果您在驱动器上安装了 Jupyter Notebook,则原理相同。转到保存 Jupyter 的文件夹,然后在地址栏上输入 Jupyter Notebook,然后按 Enter。比更改系统路径更容易..
Go to the path where python is installed (type in python to start menu and open file location). On the address toolbar, type in the version of the Python - for me it's Python 3.10 (64-bit) and press enter. The command prompt will open up with the exact path where python is saved, so that the code will work. Same principle if you have installed Jupyter Notebook on your drive. Go to the folder where Jupyter is saved and type in Jupyter Notebook on the address bar and press enter. Easier than changing system paths..
对于 Windows 8,只需输入“py”。
For windows 8, just type "py".