python - 艰难地学习 Python,Ex 2; Powershell 不输出 ex1.py?

标签 python powershell environment-variables

我对这门语言还很陌生,所以我可能需要 ELI5 来回答。

我已经创建了我的 ex1.py,检查了所有的大小写和语法,它似乎是正确的?

print "Hellow World!"
print "Hello again"
print "i like typing this" 
print "this is fun"
print 'Yay! printing!' 
print "I'd much rather you 'n'."
print 'I "said" do not touch this!'

当我在导航到正确的文件夹后在终端中键入:python ex1.py 时,终端显示脚本,而不是 powershell。 我试过输入

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

等将本书第 8 页上的字符串导入 PowerShell,但这似乎无济于事。

在上面的文件路径中,我是否应该将 C:\Python27 替换为我安装 Python 的位置的文字文件路径?同样,“用户”与我的用户名?还是按原样输入字符串?

最佳答案

您的代码没问题,但似乎您的环境设置不正确。执行以下操作:

  1. 启动powershell
  2. [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\<directory_where_python.exe in installed>", "User")

  3. 重启 powershell(关闭它,然后重新启动它)

  4. cd到包含ex1.py的目录

  5. 执行 python .\ex1.py

关于python - 艰难地学习 Python,Ex 2; Powershell 不输出 ex1.py?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47207892/

相关文章:

java - 在java中执行powershell命令时出现TerminatorExpectedAtEndOfString错误

database - Ktor与Gradle从环境变量运行配置 “Could not resolve substitution to a value”

ssl - Docker HTTPS 访问 - ONLYOFFICE3

python - 基于 Python 中的颜色过滤器绘制区域

python - 如何使用 map 和 reduce 在 Python 中按步骤组成函数列表

python - 当 edgecolor = 'none' 时 Matplotlib 标记消失

python - 使用 Flask Cache 和 memcached 存储简单的键值对

com - 有什么方法可以终止 Powershell 中的挂起进程吗?

c# - 在 C# 中使用 PowerShell 导入 CSV 添加列

c++ - 从配置文件读取路径