标签归档:cmd

无法将“ python”识别为内部或外部命令[重复]

问题:无法将“ python”识别为内部或外部命令[重复]

因此,我最近安装了Python版本2.7.5,并对其进行了一些循环处理,但是问题是,当我转到cmd并键入时python testloop.py,出现错误:

无法将“ python”识别为内部或外部命令

我尝试设置路径,但无济于事。

这是我的路:

C:\ Program Files \ Python27

如您所见,这是安装Python的地方。我不知道该怎么办 有人可以帮忙吗?

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?


回答 0

您需要将该文件夹添加到Windows路径:

https://docs.python.org/2/using/windows.html来自这个问题。

You need to add that folder to your Windows Path:

https://docs.python.org/2/using/windows.html Taken from this question.


回答 1

从命令行尝试“ py”而不是“ python”:

C:\ Users \ Cpsa> py
Python 3.4.1(v3.4.1:c0e311e010fc,2014年5月18日,10:38:22)[win32 MSC v.1600 32 bit(Intel)]
键入“ help”,“ copyright” ,“信用”或“许可证”以获取更多信息。
>>>

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.
>>>


回答 2

我找到了答案…单击安装程序,然后选中“将python添加到环境变量”框。不要卸载旧版本,而是单击“修改…”。单击图片链接…

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…


回答 3

首先,请确定您的python目录在哪里。通常在C:\Python27。如果您的不同,请从以下命令进行更改。

如果安装后仍无法识别python,请在PowerShell中输入以下内容:

[环境] :: SetEnvironmentVariable(“路径”,“ $ env:路径; C:\ Python27”,“用户”)

关闭PowerShell,然后再次启动以确保Python现在可以运行。如果不是,则可能需要重新启动。

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.


回答 4

在命令提示符下键入py -v而不是python -v

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


回答 5

如果要查看python版本,则应使用py -V而不是python -V

C:\ Users \ ghasan> py -V

的Python 3.7.1

如果要转到python的运行环境,则应使用py而不是python

C:\ Users \ ghasan> py

在Win32上的Python 3.7.1(v3.7.1:260ec2c36a,2018年10月20日,14:57:15)[MSC v.1915 64位(AMD64)]

键入“帮助”,“版权”,“信用”或“许可证”以获取更多信息。

在这里,您可以按照以下方式运行python程序:

打印(’Hello Python’)

你好Python

If you want to see python version then you should use py -V instead of python -V

C:\Users\ghasan>py -V

Python 3.7.1

If you want to go to python’s running environment then you should use py instead of python

C:\Users\ghasan>py

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

Here you can run the python program as:

print(‘Hello Python’)

Hello Python


回答 6

我通过在管理模式下运行CMD解决了此问题,因此请尝试此操作。

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


回答 7

我在安装Python时遇到了同样的问题,并且在系统中设置PATH时可以解决此问题,请按以下步骤操作。

  • 导航到“控制面板”->“系统”
  • 点击左侧的“高级系统设置”
  • 点击“环境变量”
  • 搜索并单击“路径”变量
  • 点击“编辑”
  • 如果您使用的是Windows7,请在环境变量字段中添加“ C:\”,然后用分号将其与现有条目分开。如果您使用的是Windows10,只需单击“新建”即可添加。
  • 重新打开命令提示符,然后尝试 在此处输入图像描述

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

回答 8

打开具有管理访问权限的CMD(右键单击,然后以管理员身份运行),然后在此处键入以下命令:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

将My_python_lib替换为已安装的python的文件夹名称,就像我这样C:\python27。然后检查是否设置了path变量,键入,echo %PATH%您将在最后看到python部分。因此,现在python可以访问了。 从本教程

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 echo %PATH% you’ll see your python part in the end. Hence now python is accessible. From this tutorial


回答 9

在Python 文档中,像上面一样设置PATH。

您应该安排在开始时将Python的安装目录添加到每个命令窗口的PATH中。如果您是最近安装的Python,则命令dir C:\ py *可能会告诉您它的安装位置。通常的位置类似于C:\ Python27。否则,您将只能搜索整个磁盘

使用工具‣查找或单击搜索按钮,然后查找“ python.exe”。假设您发现Python安装在C:\ Python27目录(编写本文时的默认目录)中,则应确保输入以下命令

然后使用完整路径名执行Python命令,以确保其有效。

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

Use Tools ‣ Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command

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


回答 10

如果Python在PATH变量中,则另一个有用但简单的解决方案可能是在下载后重新启动计算机。当我将Python下载到新计算机上时,这通常是一个错误。

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.


回答 11

我已经安装了python 3.7.4。首先,我在命令提示符下尝试了python。有人说“ Python无法识别命令……”。然后我尝试了“ py”命令,它可以工作。

我的示例命令是:

py hacker.py

I have installed python 3.7.4. First, I tried python in my command prompt. It was saying that ‘Python is not recognized command……’. Then I tried ‘py’ command and it works.

My sample command is:

py hacker.py

回答 12

如果先卸载后重新安装,然后在CLI中运行“ python”,请确保在安装后打开新的CMD,以便识别“ python”。py可能会被旧的CLI识别,因为它与任何版本无关。

If you uninstalled then re-installed, and running ‘python’ in CLI, make sure to open a new CMD after your installation for ‘python’ to be recognized. ‘py’ will probably be recognized with an old CLI because its not tied to any version.


回答 13

选项1:在安装过程中选择添加环境变量。选项2:转到C:\ Users-> AppData(隐藏文件)-> Local \ Programs \ Python \ Python38-32(取决于安装的版本)\ Scripts复制路径并添加到env vars路径。

对我而言,此路径有效:C:\ Users \ Username \ AppData \ Local \ Programs \ Python \ Python38-32 \ Scripts

Option 1 : Select on add environment var during installation Option 2 : Go to C:\Users-> AppData (hidden file) -> Local\Programs\Python\Python38-32(depends on version installed)\Scripts Copy path and add to env vars path.

For me this path worked : C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts


回答 14

将SQL Server 2019与Python一起安装后,它与Python指令更加混乱。我发现的实际路径如下:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

脚本使用Execute命令运行:

Declare @script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script @language = N'Python', @script = @script

还有其他参考SQL 2019版本的Python的文档。有一条声明建议仅从git(https://www.github.com/Microsoft/sqlmutils)上的sqlmutils-xxxzip下载中使用PIP,但有一个警告。目前,这仅适用于R,不适用于Python(Anaconda,因此为pip)。Python over SQL可以运行,但是pip尚不可用。(11/25/2019)

发生这种情况时,获得更新会很棒。

It was a bit more confusing with the Python instructions once SQL Server 2019 was installed with Python. The actual path I find is as follows:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

Scripts run with an Execute command:

Declare @script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script @language = N'Python', @script = @script

There is additional documentation in reference to SQL 2019’s version of Python. There is a statement that recommends PIP be used only from a download of sqlmutils-x.x.x.zip located on git (https://www.github.com/Microsoft/sqlmutils) But there is a caveat. Currently this only works for R and not for Python (Anaconda and consequently pip). Python over SQL works but pip is not yet available. (11/25/2019)

Would be great to get an update when this occurs.