簡體   English   中英

PyInstaller打包的flask應用程序無法加載Python庫,dlopen->找不到映像

[英]PyInstaller packaged flask app failes to load Python Library, dlopen -> image not found

我使用PyInstaller打包了一個簡單的 Flask 應用程序,但是我的OSX可執行文件無法運行,並顯示以下可執行文件,

Error loading Python lib '/Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/Python': dlopen(/Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/Python, 10): image not found

我的猜測是PyInstaller沒有將Python與我的應用程序打包在一起。 這是我跑的

$ pyinstaller hello_flask.spec --onedir
83 INFO: PyInstaller: 3.2
83 INFO: Python: 3.4.3
87 INFO: Platform: Darwin-13.4.0-x86_64-i386-64bit
89 INFO: UPX is not available.
90 INFO: Extending PYTHONPATH with paths
['/Users/ahmed/Code/play/py-install-tut',
 '/Users/ahmed/Code/play/py-install-tut']
90 INFO: checking Analysis
99 INFO: checking PYZ
104 INFO: checking PKG
105 INFO: Building because toc changed
105 INFO: Building PKG (CArchive) out00-PKG.pkg
144 INFO: Bootloader /opt/boxen/pyenv/versions/3.4.3/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/bootloader/Darwin-64bit/run_d
144 INFO: checking EXE
145 INFO: Building because toc changed
145 INFO: Building EXE from out00-EXE.toc
145 INFO: Appending archive to EXE /Users/ahmed/Code/play/py-install-tut/build/hello_flask/hello_flask
155 INFO: Fixing EXE for code signing /Users/ahmed/Code/play/py-install-tut/build/hello_flask/hello_flask
164 INFO: checking COLLECT
WARNING: The output directory "/Users/ahmed/Code/play/py-install-tut/dist/hello_flask" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
1591 INFO: Removing dir /Users/ahmed/Code/play/py-install-tut/dist/hello_flask
1597 INFO: Building COLLECT out00-COLLECT.toc
2203 INFO: checking BUNDLE
WARNING: The output directory "/Users/ahmed/Code/play/py-install-tut/dist/myscript.app" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
3947 INFO: Removing dir /Users/ahmed/Code/play/py-install-tut/dist/myscript.app
3948 INFO: Building BUNDLE out00-BUNDLE.toc
3972 INFO: moving BUNDLE data files to Resource directory

當我在OSX中打開打包的應用程序的內容時,我得到以下文件,

myscript.app/Contents/MacOS/
  _struct.cpython-34m.so
  hello_flask
  zlib.cpython-34m.so

當我雙擊上面的hello_flask可執行文件時,我在終端中獲得以下輸出,

/Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask ; exit;                        
PyInstaller Bootloader 3.x
LOADER: executable is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask
LOADER: homepath is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS
LOADER: _MEIPASS2 is NULL
LOADER: archivename is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask
LOADER: Extracting binaries
LOADER: Executing self as child
LOADER: set _MEIPASS2 to /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS
PyInstaller Bootloader 3.x
LOADER: executable is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask
LOADER: homepath is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS
LOADER: _MEIPASS2 is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS
LOADER: archivename is /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask
LOADER: Already in the child - running user's code.
LOADER: Python library: /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/Python
Error loading Python lib '/Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/Python': dlopen(/Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/Python, 10): image not found
LOADER: Back to parent (RC: 255)
LOADER: Doing cleanup
LOADER: Freeing archive status for /Users/ahmed/Code/play/py-install-tut/dist/myscript.app/Contents/MacOS/hello_flask

[Process completed]

我也嘗試在同事的Mac OSX上運行此命令,但遇到了同樣的問題。

我確實意識到這是一個古老的帖子,但是遇到了同樣的問題,並找到了可能的解決方案-以防萬一其他人覺得它有用。 可能不是很理想,我敢肯定某個地方一定缺少什么,但是無論如何...

pyinstaller在dist目錄中創建一個myscript目錄和一個myscript.app文件。 我設法通過手動將dist / myscript中的所有內容復制到myscript.app/Contents/MacOS中來使應用程序運行

之后,myscript.app文件為我成功啟動了該程序,也可以在沒有myscript目錄的情況下進行分發。

不知道為什么pyinstaller不會自動復制所有內容。

正如Ireneusz在他們的帖子中提到的那樣,您可以從“ hello_flask”文件夾中復制該捆綁包,這樣便可以使用,但是要提供有關如何讓PyInstaller為您完成工作的更多信息,請按以下方式編輯BUNDLE spec類:

a = Analysis(...
pyz = PYZ(a...
exe = EXE(pyz, a...
coll = COLLECT(exe, a...
app = BUNDLE(coll,...

如果將BUNDLE類指向COLLECT對象而不是EXE,則生成將像使用非應用程序包dist一樣捆綁所有部分。 如您所見,每個類都以某種方式嵌套到下一個類中,因此這只會將您的構建嵌套到包中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM