简体   繁体   English

Py2app使用控制台还是gui,但不能同时使用两者?

[英]Py2app either uses console or gui, but not both?

My program runs perfectly when launched through terminal or the PythonLauncher. 通过终端或PythonLauncher启动时,我的程序可以完美运行。 My program utilizes both a GUI written through pyside and a terminal console. 我的程序同时使用通过pyside编写的GUI和终端控制台。 When I wrap my program using py2app, running the produced .app file yields only the GUI, not the terminal shell. 当我使用py2app包装程序时,运行生成的.app文件仅生成GUI,而不生成终端外壳。 My program, therefore, does not work, because it is unable to call sub-processes in the terminal shell without the terminal shell being open. 因此,我的程序无法正常工作,因为在没有打开终端外壳的情况下无法调用终端外壳中的子进程。

Any ideas as to how I can have both the terminal shell and the GUI open? 关于如何同时打开终端外壳和GUI的任何想法? I assume this is an error with my setup.py or my py2app settings. 我认为这是我的setup.py或py2app设置错误。 Here's my setup.py 这是我的setup.py

from setuptools import setup

APP = ['myProgram.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

...and here's the terminal command I'm using to compile my application with py2app ...这是我正在使用py2app编译应用程序的终端命令

python setup.py py2app

Thanks for the help, everyone! 谢谢大家的帮助!

Applications created by py2app are GUI application bundles and don't open a terminal window. py2app创建的应用程序是GUI应用程序捆绑包,不会打开终端窗口。 If you really need a terminal window, instead of using a GUI window for input, you can launch the application from a terminal window ("MyApp.app/Contents/MacOS/MyApp" if your application is named MyApp). 如果您确实需要一个终端窗口,而不是使用GUI窗口进行输入,则可以从终端窗口(如果您的应用程序名为MyApp,则为“ MyApp.app/Contents/MacOS/MyApp”)启动该应用程序。

BTW. BTW。 I don't understand what you mean by "have to call the terminal by subprocess.call". 我不明白“必须通过subprocess.call调用终端”的含义。 Running command-line tools using subprocess works just fine in an application bundle, unless you need to interact with that process (for example because you are launching a TTY editor like vim or emacs). 使用子进程运行命令行工具在应用程序包中运行良好,除非您需要与该进程进行交互(例如,因为您正在启动vim或emacs之类的TTY编辑器)。

When you build the setup.py using py2applet, you might try using the --emulate-shell-environment option: 使用py2applet构建setup.py时,可以尝试使用--emulate-shell-environment选项:

python setup.py py2app --emulate-shell-environment

My application opens up a Terminal window when run if I build using that option. 如果我使用该选项进行构建,则我的应用程序在运行时会打开一个终端窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM