Pyinstaller exe打开然后立即关闭,这是我试图转换为.exe的python代码:
from cefpython3 import cefpython as cef
import platform
import sys
def main():
check_versions()
sys.excepthook = cef.ExceptHook
cef.Initialize()
cef.CreateBrowserSync(url="https://funkytime.tv/",
window_title="funkytime.tv")
cef.MessageLoop()
cef.Shutdown()
def check_versions():
ver = cef.GetVersion()
print("[hello_world.py] CEF Python {ver}".format(ver=ver["version"]))
print("[hello_world.py] Chromium {ver}".format(ver=ver["chrome_version"]))
print("[hello_world.py] CEF {ver}".format(ver=ver["cef_version"]))
print("[hello_world.py] Python {ver} {arch}".format(
ver=platform.python_version(),
arch=platform.architecture()[0]))
assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"
if __name__ == '__main__':
main()
可能与cefpython3模块有关。
Pyinstaller不会编译失败,但是当我打开.exe时,它将打开然后立即关闭,这是cmd吐出的错误:
Traceback (most recent call last):
File "test.py", line 1, in <module>
from cefpython3 import cefpython as cef
File "c:\users\noahd\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
if the named module was loaded. If the module is not found, then
File "site-packages\cefpython3\__init__.py", line 59, in <module>
File "c:\users\noahd\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
File "cefpython_py36.pyx", line 137, in init cefpython_py36
ModuleNotFoundError: No module named 'json'
[11076] Failed to execute script test
帮助。 (我也尝试过py2exe和其他一些工具,但它们都不起作用)
答案 0 :(得分:0)
CEF Python有一个PyInstaller示例,请参见: https://github.com/cztomczak/cefpython/tree/master/examples/pyinstaller
“ json”包由cefpython模块内部使用,并且已通过pyinstaller配置中的hiddenimport
添加,请参见:
https://github.com/cztomczak/cefpython/blob/2c99e06b338396bfb24c20be61c3802e245f9a77/examples/pyinstaller/hook-cefpython3.py#L170