Python 3.6无法通过命令提示符运行

问题描述 投票:0回答:2

问题:

我在“Path”和“PYTHONPATH”系统变量中都包含了Python的安装路径(C:\ Program Files \ Python36)。我暂时不需要使用Python,我确信它上次工作(接近几个月前)。 Python IDLE仍然有效,但我需要通过命令提示符使用Python。

我在网上找到的其他类似问题通常都是通过对系统变量进行适当的更改来解决的。

尝试执行任何与Python相关的任务时出现错误消息: python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + python + ~~~~~~ + CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

到目前为止我做了什么:

  • 通过控制面板>系统和安全>系统>高级系统设置>环境变量将系统变量设置为Python路径
  • 尝试使用cd直接从它的安装位置使用python
python windows python-3.x windows-10
2个回答
-1
投票

您是否更改了命令提示符的目录?如果您正在尝试打开shell,请尝试执行以下操作:

cd C:\Program Files\Python36

在你打字之前

python 

引导shell。

Java的编译也出现了类似的问题,出于某些原因,设置环境变量不会削减它。如果您正在尝试运行预先编写的程序,请尝试:

set path="C:\Program Files\Python36"

等效目录适用于Java。然后将自己定位到文件的位置:

cd C:\location

我希望这是你想要的。 ☺️


-1
投票

解:

Python的安装路径被Visual Studio覆盖到它的“共享”位置(更像是痛苦的位置)位于:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\

改变两个系统变量(PathPYTHONPATH )到这个位置解决了这个问题。

感谢所有评论/回复的人。

编辑:显然,手动设置PYTHONPATH是不好的做法,因为它是由Python自动设置的。

© www.soinside.com 2019 - 2024. All rights reserved.