经过多次尝试,我终于找到了编译我的 Cefpython 代码的方法:
import json
import urllib.request
from cefpython3 import cefpython as cef
import platform
import sys
url = "https://google.com/"
def main():
check_versions()
sys.excepthook = cef.ExceptHook
cef.Initialize()
cef.CreateBrowserSync(url=url,
window_title="browser")
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()
(有 jason 和 urllib.request 以便编译器(py2exe pyinstaller 等)不会出错)
使用 cx_Freeze 但是当我运行 exe cx_freeze 时会发生这种情况:
[0930/071436.905:ERROR:main_delegate.cc(710)] Could not load locale pak for en-US
[0930/071436.906:ERROR:main_delegate.cc(717)] Could not load cef.pak
[0930/071436.906:ERROR:main_delegate.cc(734)] Could not load cef_100_percent.pak
[0930/071436.906:ERROR:main_delegate.cc(743)] Could not load cef_200_percent.pak
[0930/071436.907:ERROR:main_delegate.cc(753)] Could not load cef_extensions.pak
[0930/071436.926:ERROR:content_client.cc(272)] No data resource available for id 101
(来自 debug.log)
我认为这是cefpython的事情,但我不知道。