python - 尝试从 Powershell 运行 python 程序时,Powershell 提示返回提示但不返回 Python 输出
问题描述
我正在尝试从 powershell 运行 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 目录中,其中包含一行:
打印“你好世界!”
我试着同时输入
python helloworld.py
.\python helloworld.py
第一个返回原始错误,第二个再次返回提示,显然没有做任何事情,我无法让 python 程序运行。我是 Powershell 和 Pyton 的新手,我正在努力学习 python,任何人都可以帮助或指出我哪里出错并解释我做错了什么以及解决方案是什么?谢谢
解决方案
你应该可以通过告诉 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”</p>
推荐阅读
- javascript - 如果填充,更改输入字段颜色
- sql - 过去 6 个月内每个月听超过 10 分钟的人
- javascript - 关于使用 webpack 在 javascript 中的语法
- jsp - Tomcat 9 和 Web 应用程序子目录的类路径问题
- javascript - 节点 Postgres Pub/Sub - 保留剩余的连接槽
- mod-rewrite - mod rewrite 3 个子域重定向到自己(通用重定向)
- c# - 如何使用 HashCode.Combine 避免冲突?
- python - Python - 在 floweaver 中合并包
- python-3.x - 在“.eml”中编辑标题
- c# - 在 C# 外部单击后如何删除按钮边框?