Error loading Python lib with PyInstaller on MacOS

主宰稳场 提交于 2020-06-25 04:45:12

问题


I am trying to package some python into an executable on MacOS (10.14.5). I am able to create the executable, but executing the resulting dist/hello_world executable gives the following error:

[55240] Error loading Python lib '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python': dlopen: dlopen(/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python, 10): no suitable image found.  Did find:
    /var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python: code signature invalid for '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python'

My machine is running Python 3.7.7 installed from using the Mac installer downloaded from https://www.python.org/

For now, the script I am trying to package only contains print('hello world!') and the packaging command I am using is pyinstaller -F hello_world.py


回答1:


I had success using pyenv and installing the specific version of python with the enable framework option:

env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.6

With this version of python (set using the command pyenv local 3.7.6 in the folder where hello_world.py is located), install pyinstaller (and any other modules you need) with pip. Then build with

pyinstaller hello_world.py --onefile --clean --windowed

which should give you a functioning dist/hello_word. As a python fledgling, I have no idea why this works as opposed to the steps in the original question. (I thought the Mac OS installer included the Python.framework by default -- I'm sure my ignorance is exposed here as this probably differs significantly from what the PYTHON_CONFIGURE_OPTS variable is doing above).

Also possible to do all this within a virtual environment (easily managed by pyenv-virtualenv).



来源:https://stackoverflow.com/questions/60678697/error-loading-python-lib-with-pyinstaller-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!