首页 > 解决方案 > 每当我尝试在命令行中运行 python 脚本时出现“找不到 '__main__' 模块”错误

问题描述

这是我的批处理文件代码:

@py C:\Users\Asus\Google Drive\Lifestyle\Technicals\Programming\Python\Python Scripts\Test.py %*
@pause

或者,当我在命令行中尝试这行代码时,也会出现同样的错误:

py.exe C:\Users\Asus\Google Drive\Lifestyle\Technicals\Programming\Python\Python Scripts\Test.py

我的 Test.py 文件有:

print('Hello')

错误信息: 在此处输入图像描述

标签: python

解决方案


你能试试吗

python "C:\Users\Asus\Google Drive\Lifestyle\Technicals\Programming\Python\Python Scripts\Test.py"

命令行不喜欢“”(空格)字符。从而破坏了你的命令。

您需要cd directory在正确的目录中或执行用双引号括起来的命令


推荐阅读