【发布时间】:2017-07-24 14:07:40
【问题描述】:
以下代码无法启动 python 命令行。
QProcess *myProcess = new QProcess(this);
myProcess->start("\"C:\\Program Files\\Python27\\python.exe\"");
如果我用(例如)替换 python27
myProcess->start("\"C:\\Program Files\\Notepad++\\notepad++.exe\"")
记事本打开。为什么我的程序可以启动记事本,但不能启动 Python 命令行?
我尝试按照here 的建议使用 startDetached() ,但这并没有什么不同。
QProcess::Error() 给我错误 5:未知错误。
【问题讨论】:
-
你到底想用python做什么? python.exe 是解释器二进制文件,所以如果你想运行一个特定的 .py 脚本,你需要将它作为参数传递给 python,但是从命令行(运行 cmd.exe 行而不是 python 与 'python script.py' as论据)
-
@t020608 你确定
python.exe运行正常吗?喜欢双击它? -
@Lucian 现在我只是想看看我是否可以打开 python。从长远来看,我想执行在我的 Qt GUI 中创建的 python 脚本(最好能够监控进度并暂停脚本)。那我应该使用命令行吗?
-
我刚刚在 Qt5.5 和 python 3.6 中运行了你的代码。
myProcess->start(...)什么都没有发生,但QProcess::startDetached(...)工作。你确定路径是正确的吗?也许python安装在C:\Program Files (x86)而不是C:\Program Files。你确定你没有犯任何拼写错误吗? -
@pschill 我确定我的路径是正确的,因为我可以使用
system("start C:\\Python27\\python.exe");启动 python(我更改了 Python27 文件夹的位置)