最起初遇到的問題,由於我在pycharm下virtualenv做的
No module named 'gevent.__hub_local'
本機環境打包的問題
顯示找不到
C:XXXX/temp/xxxx/eel/eel.js
於是打開了python下的eel包
將文件下的
__init__.py 第17行
#_eel_js_file = pkg.resource_filename('eel', 'eel.js')
#_eel_js = open(_eel_js_file, encoding='utf-8').read()
注釋掉
新添加
eel_js=eelJS.eelJS
在上面導入eelJS模塊
自己在eel模塊中新建一個python文件,名字為eelJS,文件內容是eel.js文件中的內容
后來想把編譯好的軟件去掉控制台,看到網上都是用 python -m eel py腳本文件 web靜態文件目錄 --onefile來打包的,並不知道其中打包的原理,后來打開eel模塊下的
__main__.py文件
from __future__ import print_function
import sys
import pkg_resources as pkg
import PyInstaller.__main__ as pyi
import os
args = sys.argv[1:]
main_script = args.pop(0)
web_folder = args.pop(0)
print("Building executable with main script '%s' and web folder '%s'...\n" %
(main_script, web_folder))
eel_js_file = pkg.resource_filename('eel', 'eel.js')
js_file_arg = '%s%seel' % (eel_js_file, os.pathsep)
web_folder_arg = '%s%s%s' % (web_folder, os.pathsep, web_folder)
needed_args = ['--hidden-import', 'bottle_websocket',
'--add-data', js_file_arg, '--add-data', web_folder_arg]
full_args = [main_script] + needed_args + args
print('Running:\npyinstaller', ' '.join(full_args), '\n')
pyi.run(full_args)
底層調用的也是pyinstaller,所以有了下面的命令,直接將需要的命令寫在后面
我需要打包的pyton文件是 document.py 額外需要加入打包的目錄是web
python -m eel document.py web -Fw -i web/images/ico.ico