- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个应用程序,其中有两个可执行文件:Flask-SocketIO-Server 和 CefPython 浏览器。我将这两个可执行文件与 PyInstaller 捆绑在一起。带有 --onefile 选项的 Flask-Server 和带有 --onedir 选项的 cefpython,因为我无法使用 --onefile。现在我决定只为这两种代码(Flask 和 CEFpython)提供可执行文件,所以我的 Flask 服务器有运行 CEF 图形用户界面的代码:
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == 'dev':
print "Running Flask-SocketIO on dev mode"
else:
print "Running Flask-SocketIO on production mode"
path = os.getcwd()
gui_path = path + '\\display_react\\display_react.exe'
print 'Running Graphical User Interface...'
thread.start_new_thread(display_react.main, ()) # Baterias
print 'Initializing server'
socketio.run(app, debug=False)
代码运行良好,但当我尝试使用 --onefile 选项将此代码与 PyInstaller 捆绑在一起时,生成的可执行文件无法运行,导致某些 CEF 依赖项。运行 Pyinstaller 时出现以下错误:
Running Flask-SocketIO on production mode Running Graphical User Interface... Initializing server [wxpython.py] CEF Python 57.1 [wxpython.py] Python 2.7.14 64bit [wxpython.py] wxPython 4.0.1 msw (phoenix) [0727/125110.576:ERROR:main_delegate.cc(684)] Could not load locale pak for en-US [0727/125110.576:ERROR:main_delegate.cc(691)] Could not load cef.pak [0727/125110.578:ERROR:main_delegate.cc(708)] Could not load cef_100_percent.pak [0727/125110.582:ERROR:main_delegate.cc(717)] Could not load cef_200_percent.pak [0727/125110.582:ERROR:main_delegate.cc(726)] Could not load cef_extensions.pak [0727/125110.648:ERROR:content_client.cc(269)] No data resource available for id 20418 [0727/125110.648:ERROR:content_client.cc(269)] No data resource available for id 20419 [0727/125110.650:ERROR:content_client.cc(269)] No data resource available for id 20420 [0727/125110.655:ERROR:content_client.cc(269)] No data resource available for id 20421 [0727/125110.656:ERROR:content_client.cc(269)] No data resource available for id 20422 [0727/125110.656:ERROR:content_client.cc(269)] No data resource available for id 20417 [0727/125110.680:ERROR:extension_system.cc(72)] Failed to parse extension manifest. C:\Users\Ricardo\AppData\Local\Temp_MEI95~1\display_react.py:118: wxPyDeprecationWarning: Call to deprecated item EmptyIcon. Use :class:
Icon
instead
这里是我正在使用的 .spec 文件:
# -*- mode: python -*-
block_cipher = None
def get_cefpython_path():
import cefpython3 as cefpython
path = os.path.dirname(cefpython.__file__)
return "%s%s" % (path, os.sep)
cefp = get_cefpython_path()
a = Analysis(['server.py'],
pathex=['C:\\Users\\Ricardo\\addvolt-scanning-tool\\backend'],
binaries=[],
datas=[('PCANBasic.dll', '.'), ('o.ico', '.')], #some dlls i need for flask
hiddenimports=['engineio.async_gevent'], #engineio hidden import for Flask usage
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas + [('locales/en-US.pak', '%s/locales/en-US.pak' % cefp, 'DATA')], # my try to fix that missing dependencies
name='server',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
编辑:已解决
多亏了@cztomczak,我才开始工作。问题不在 PyInstaller 上,而是在 wxpython.py 寻找语言环境、资源和子进程的过程中。尽管所有文件都在“temp/dir/_MEIxxx”中,但 wxpython 正在可执行文件的目录中寻找这些文件。所以我通知代码在临时目录中查找这些文件的方法是:
dir_temp = tempfile.gettempdir()
files = []
for i in os.listdir(dir_temp):
if os.path.isdir(os.path.join(dir_temp,i)) and '_MEI' in i:
files.append(i)
dir_temp = dir_temp + str(files[0])
dir_temp = os.path.join(dir_temp, str(files[0]))
dir_temp_locale = os.path.join(dir_temp, 'locales')
dir_temp_subprocess = os.path.join(dir_temp_subprocess, 'subprocess.exe')
print dir_temp
dir_temp = dir_temp.replace("\\", "\\\\")
print dir_temp
print dir_temp_locale
dir_temp_locale = dir_temp_locale.replace("\\", "\\\\")
print dir_temp_locale
dir_temp_supbprocess = dir_temp_subprocess.replace("\\", "\\\\")
print dir_temp_subprocess
...
settings = {'auto_zooming': '-2.5', 'locales_dir_path': dir_temp_locale, 'resources_dir_path': dir_temp, 'browser_subprocess_path': dir_temp_subprocess}
我必须这样做,因为在临时 (_MEIxxxx) 上创建的文件夹的名称总是在变化。并且我将来可能会遇到问题,因为如果应用程序崩溃,_MEIxx 文件夹将不会被删除,如果我尝试重新运行可执行文件,这段代码将有两个 _MEI 文件夹,并且可能根本无法工作,直到有人清理临时目录。
所以,恢复...要将应用程序捆绑在一个文件中:- 将 hook-cefpython3.py(在包中可用)粘贴到 Python27/envs/libs/site-package/Pyinstaller/hooks- 使用 --onefile 选项运行 Pyinstaller- 告诉 cefpython 代码区域设置、资源和子进程在哪里(locale_dir_path、resource_dir_path、browser_subprocess_path)
最佳答案
我猜你得到的错误是因为你的规范文件没有包含所有必要的 CEF 二进制文件。有一个官方的 pyinstaller 示例,您可以使用和修改以使用 --onefile 选项:https://github.com/cztomczak/cefpython/blob/master/examples/pyinstaller/README-pyinstaller.md
关于python - 使用 --onefile 选项在 PyInstaller 上捆绑 CEFpython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51558349/
我有一个应用程序,我想将其打包到一个文件中,但在使用 --onefile 选项(包括 html、js 和 css 文件)时遇到了问题。该过程在运行 --onedir 时运行良好(当然是在将各个数据文件
请阅读所有这篇文章并帮助我。 我想用 pyinstaller 创建 --onefile 可执行文件。 我在开发方面有这些: Windows 8.1 x64 Qt 5.2.1 python 27 PyQ
我用“pyinstaller --onefile myapp.py”打包了一个 python 应用程序,它创建了一个可执行文件,并且该应用程序运行良好。现在我希望能够从系统中导入一个模块(如果存在),
我知道我不是第一个提问的,但论坛上的其他答案帮不了我,所以我来提问。我有一个只有导入的简短(181 行)python 脚本 import numpy as np import matplotlib.p
我正在尝试使用 PyInstaller 构建一个包含图像和图标的单文件 EXE。我一辈子都无法让它与 --onefile 一起使用。 如果我这样做 --onedir 它工作得很好。当我使用 --one
我有一个有效的 Python 3 脚本 inventoryScraper.py,我正试图将其制作成一个我可以分发的 1 文件可执行文件。我一直在将 Pyinstaller 3 与 Python 3 一
我正在尝试将图像添加到 Pyinstaller 生成的一个文件中。我读过很多这样的问题/论坛 one那one但仍然无法正常工作。 我知道对于一个文件操作,PyinSTLler 会生成一个可以通过 sy
我正在尝试将包含图像的文件夹嵌入到生成的(使用 PyInstaller)可执行文件中。但这对我不起作用。即使只有一张简单的图片! 我的 main.spec 文件中的 datas 变量如下所示: dat
我正在尝试使用 pyinstaller 打包 cli 应用程序(当前适用于 macos)。我阅读 pyinstaller 文档的最初印象是,当使用 --onefile 选项时,我将能够将所有必需的文件
我正在尝试使用 Pyinstaller 构建单文件 EXE 文件,它包含 Sqlite 数据库文件,它不能与 --onefile 一起使用,但在正常情况下意味着(许多文件)它工作 100%。 我正在做
我正在尝试使用 PyInstaller 2.0 将我的 py 脚本捆绑为 .exe。我可以捆绑脚本,但在我的脚本中,我需要打开一个应该捆绑在 exe 中的文件(因此它是可移植的)。我在执行此操作时遇到
我听到 3 年前的问题,显然有无穷大的解决方案。我想找到这个无限集合中的一个。 问题: 编写程序(只有一个文件示例“selfsource.c”)在 stdout 上打印自己的源代码并退出。 所有技术都
我有一个应用程序,其中有两个可执行文件:Flask-SocketIO-Server 和 CefPython 浏览器。我将这两个可执行文件与 PyInstaller 捆绑在一起。带有 --onefile
我创建了一个 exe 文件,它在某些 Windows 机器上运行良好,但在其他机器上运行失败。 我还找不到失败的原因。 重要数据: x64 可执行程序 Windows 7 python 3.5.1 p
我正在使用 PyInstaller 使用 .spec 文件“编译”一个程序。我正在使用 .spec 文件,因为我需要在程序中包含一个额外的文件。当我尝试执行 PyInstaller --onefile
我已经从 python tkinter GUI 成功创建了一个包含图像的 EXE 文件。请参阅以下代码: lblLogo=Label(main) lblLogo.grid(row=3,column=1
我正在尝试使用 PyInstaller 1.5 编译 PyQt 程序。当我使用 --onedir(默认)时,以下两个程序对我来说都很好,但这会创建相当大的程序。我想使用 --onefile 选项,但是
我已经使用 Pyinstaller 创建了一个 exe 文件。 pyinstaller.exe --onefile --icon='Loco.ico program.py 在该程序中,我在绘图中包含了
我有一个小脚本,它使用 tableau rest api 从 tableau View 下载数据。由于脚本在公司环境中运行,因此我必须使用 SSL。那就是 python-certifi-win32 的
我正在使用 PyInstaller 将我的应用程序捆绑到一个 .exe 文件中。 问题是它可以使用 --onedir 选项正常工作,但是使用 --onefile 构建时找不到模块。 --onedir
我是一名优秀的程序员,十分优秀!