python is not recognized_'python' is not recognized as an internal or external command

本文解答了在安装Python后遇到的cmd中输入python命令无法识别的问题,提供了多种解决方案,包括设置环境变量、使用不同命令、修改路径配置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.py I get the error: 'python' is not recognized as an internal or external command

I have tried setting the path but no avail.

Here is my path: C:\Program Files\Python27

As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?

回答1:

You need to add that folder to your Windows Path:

回答2:

Try "py" instead of "python" from command line: C:\Users\Cpsa>py

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>>

回答3:

I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...

99bdfaa80d1f704b4ca18f0f1cf027f6.png

回答4:

Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.

If after you install it python still isn’t recognized, then in PowerShell enter this: [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

Close PowerShell and then start it again to make sure Python now runs. If it doesn’t, restart may be required.

2f45d56803d51630fd0ad5e21c597303.png

回答5:

From the Python docs, set the PATH like you did as above. You should arrange for Python’s installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk

Then execute the Python command using the full path name to make sure that works.

回答6:

I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps. Navigate to "Control Panel" -> "System"

Click "Advanced system settings" on the left

Click "Environment Variables"

Search and click "Path" variable

Click "Edit"

Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.

Reopen the Command Prompt and try enter image description here

回答7:

Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.

回答8:

Type py -v instead of python -v in command prompt

回答9:

Open CMD with administrative access(Right click then run as administrator) then type the following command there: set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

Replace My_python_lib with the folder name of your installed python like for me it was C:\python27. Then to check if the path variable is set type %PATH% you'll see your python part in the end. Hence now python is accessible. From this tutorial

回答10:

i solved this by running CMD in administration mode, so try this.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值