1

我有一些简单的 cefpython 代码打开一个 url,并试图用 pyinstaller 创建一个独立的可执行文件:

我将文件从https://github.com/cztomczak/cefpython/tree/master/examples/pyinstaller复制到名为pyinstaller

我对 pyinstaller.spec 做了以下小改动

+SECRET_CIPHER = ""
...
-    ["../wxpython.py"],
+    ["../hello.py"],
...
-          icon="../resources/wxpython.ico")
+          )
 

我可以使用 python 在 Windows 上成功编译我的应用程序在使用 python 3.5.4 64 位和以下 virtualenv 的同一台机器上:

cefpython3==66.0
future==0.18.2
PyInstaller==3.2.1
pypiwin32==223
pywin32==228

我还可以使用 python 3.6.4 64 和以下 virtualenv 编译 windows:

altgraph==0.17
cefpython3==66.0
future==0.18.2
macholib==1.14
pefile==2019.4.18
PyInstaller==3.3.1
pyinstaller-hooks-contrib==2020.9
pypiwin32==223
pywin32==228
pywin32-ctypes==0.2.0

在 Linux 上编译也可以,但可执行文件无法运行。

我得到以下输出和错误:

CEF Python 66.0
Chromium 66.0.3359.181
CEF 3.3359.1774.gd49d25f
Python 3.5.2 64bit
[1013/180954.001980:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
Trace/breakpoint trap (core dumped)

版本是 python 3.5.2 64bit,virtualenv 是:

cefpython3==66.0
pkg-resources==0.0.0
PyInstaller==3.2.1

可能是什么原因?

我尝试编译的代码如下:

import platform
import sys
from cefpython3 import cefpython as cef


def check_versions():
    ver = cef.GetVersion()
    print("CEF Python {ver}".format(ver=ver["version"]))
    print("Chromium {ver}".format(ver=ver["chrome_version"]))
    print("CEF {ver}".format(ver=ver["cef_version"]))
    print("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"


def main(url="https://www.stackoverflow.com"):
    sys.excepthook = cef.ExceptHook
    check_versions()
    settings = {}
    switches = {}
    browser_settings = {}
    cef.Initialize(settings=settings, switches=switches)
    cef.CreateBrowserSync(
        url=url,
        window_title="CEF_HELLO: ",
        settings=browser_settings,
        )
    cef.MessageLoop()
    cef.Shutdown()


if __name__ == "__main__":
    main()

附录:2020-10-14:

linux 上与其他版本相同的错误:到目前为止,我尝试了 python 3.5 和 3.7

有没有人成功创建了可执行文件?我可能是,这只是示例项目及其配置的问题?

4

4 回答 4

1

As alternative, a solution could be found in PyInstaller bug 5400 Here the steps:

1- download the PyInstaller helper in CEFpython named hook-cefpython3.py from: https://github.com/cztomczak/cefpython/tree/master/examples/pyinstaller and put in the root directory of your project

2- In that file, replace the line:

from PyInstaller.compat import is_win, is_darwin, is_linux, is_py2

with:

from PyInstaller.compat import is_win, is_darwin, is_linux
is_py2 = False

3- in your PyInstaller .spec file, add the '.' to the hookspath, e.g. hookspath=['.']. I think it is also possible to add it as PyInstaller command line option.

These steps should solve the problem, until CEFPython deliver a correct version of the hook file.

于 2021-01-15T13:31:15.397 回答
0

这并不是我真正想接受的答案,但它至少是一种解决方案,并且包含信息,可能会导致更好的修复,更好的答案。

使用 strace 调试后,我发现可执行文件搜索许多文件,例如,icudtl.dat在'dist/cefapp/cefpython3 dist/cefapp/`中搜索v8_context_snapshot.binlocales/*but were copied to

一个丑陋的解决方法是在编译后执行以下操作

cd dist/cefapp/cefpython3
ln -s ../* .

并且可执行文件有效。

我敢肯定还有一个更好的非暴力解决方案,但暂时我想回答一下,以防其他人也被卡住

Probably this can be fixed in the spec file but would we need one spec file for linux and one for windows then? Perhaps there's also an option to tell the excutable to search for these files one level higer?

于 2020-10-14T11:22:34.997 回答
0

To solve this, you need to set this in your spec file:

hookspath=[r'YOUR_ENV_SITE_PACKAGES\cefpython3\examples\pyinstaller\']

And then rebuild, you will have things in the right place.

于 2021-04-20T13:07:10.260 回答
0

The following steps solved the issue for me on Windows 10, Python 3.9.5 32-bit, PyInstaller 4.3, and CEFPython 66.1:

  1. Download the hook-cefpython3.py file from here and put it into your project root directory.

  2. Run the pyinstaller command as usual but add the --additional-hooks-dir . command line option, so the command will look like this:

    pyinstaller --additional-hooks-dir . <main-file.py>

As opposed to other answers here, this anser neither requires changes of hookspath directive in pyinstaller's spec file and, as of now, nor any changes to the downloaded hook-cefpython3.py file.

于 2021-08-24T18:05:52.757 回答