我正在尝试从Powershell运行python,我使用转到了python目录
cd f:\python27
如果我键入python,则会出现以下错误(尽管它是文件夹中的exe文件):
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
Suggestion [3,General]: The command python was not found, but does exist in the
current location. Windows PowerShell does not load commands from the current
location by default. If you trust this command, instead type: ".\python". See "get-
help about_Command_Precedence" for more details.
如果键入。\ python,它什么都不做,然后再次返回提示。我在文本编辑器中创建了一个名为helloworld.py的简单文件,并将其保存到python27目录中,该目录包含一行:
打印“ Hello World!”
我尝试同时输入这两个
python helloworld.py
.\python helloworld.py
第一个返回原始错误,第二个返回提示,但显然没有做任何事情,我无法运行python程序。我是Powershell和Pyton的新手,我正尝试通过困难的方式来学习python,有人可以帮助或指出我要去哪里哪里,并解释我做错了什么以及解决方案是什么?谢谢
答案 0 :(得分:1)
通过告诉Powershell在哪里可以找到Python,您应该能够使它工作。 这可以通过设置环境变量来完成。
以管理员身份打开Powershell。 运行此代码:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Python35-32")
注意:在此处的“路径”中,添加您在系统中安装Python的路径,在我的情况下为“ C:\ Program Files \ Python35-32”。>
这应该有助于解决问题。
为此,请尝试运行:
python --version
它应该显示系统中安装的Python的版本号,这是我的系统中显示的版本:
“ Python 3.5.1”