Skip to content

Mac: generated executable throws "Error loading Python lib" for any program #5062

@arosiclair

Description

@arosiclair

Description of the issue

The generated Mac executable for any program even a basic basic "Hello, World" script does not execute correctly. Using --onedir, --onefile, and --noupx does not remedy this issue.

Context information (for bug reports)

  • Output of pyinstaller --version: PyInstaller: 4.0.dev0 (same issue in 3.6 release)
  • Version of Python: 3.7.7
  • Platform: OS X Mojave (10.14.6)
  • Did you also try this on another platform? Does it work there? Windows is working
    • start with clean installation
    • use the latest development version
    • Run your frozen program from a command window (shell) — instead of double-clicking on it
    • Package your program in --onedir mode
    • [x Package without UPX, say: use the option --noupx or set upx=False in your .spec-file
    • Repackage you application in verbose/debug mode. For this, pass the option --debug to pyi-makespec or pyinstaller or use EXE(..., debug=1, ...) in your .spec file.

A minimal example program which shows the error

A bash script that will generate this issue:

# make a test folder
rm -rf mac-test
mkdir mac-test
cd mac-test/

# create a virtual environment and install pyinstaller
python3 -m venv .venv
source .venv/bin/activate
python --version
pip --version
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
pyinstaller --version

# build a hello, mac program
echo "print('hello, mac')" > main.py
pyinstaller main.py --onedir --noupx

# run the executable
./dist/main/main

Stacktrace / full error message

The executable error:

[9742] Error loading Python lib '/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python': dlopen: dlopen(/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python, 10): no suitable image found.  Did find:
        /Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python: code signature invalid for '/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python'

The full log from the above script

Python 3.7.7
pip 19.2.3 from /Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/pip (python 3.7)
Collecting https://github.com/pyinstaller/pyinstaller/archive/develop.zip
  Using cached https://github.com/pyinstaller/pyinstaller/archive/develop.zip
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting macholib>=1.8; sys_platform == "darwin" (from pyinstaller==4.0.dev0)
  Using cached https://files.pythonhosted.org/packages/3c/e1/c12f8d6af5d745ce88f270aeb243cb2bd6d8186320e5122df87fded29e4e/macholib-1.14-py2.py3-none-any.whl
Collecting altgraph (from pyinstaller==4.0.dev0)
  Using cached https://files.pythonhosted.org/packages/ee/3d/bfca21174b162f6ce674953f1b7a640c1498357fa6184776029557c25399/altgraph-0.17-py2.py3-none-any.whl
Collecting pyinstaller-hooks-contrib>=2020.6 (from pyinstaller==4.0.dev0)
  Using cached https://files.pythonhosted.org/packages/28/47/ba60fc1e96e47391dc547f74b31daf28daa3ad3b8bfc3dedced5acbf48bd/pyinstaller_hooks_contrib-2020.6-py2.py3-none-any.whl
Requirement already satisfied: setuptools in ./.venv/lib/python3.7/site-packages (from pyinstaller==4.0.dev0) (41.2.0)
Building wheels for collected packages: pyinstaller
  Building wheel for pyinstaller (PEP 517) ... done
  Created wheel for pyinstaller: filename=pyinstaller-4.0.dev0-cp37-none-any.whl size=2812826 sha256=777fbddaf34fe73d053a1eca5b6e606e9f6e6310d5be0f451a57623f4c839f2b
  Stored in directory: /private/var/folders/mm/lv7xny1n2nq8f2jw_8zz58qmkkgczp/T/pip-ephem-wheel-cache-10aawko1/wheels/1e/5b/0a/b7b241e8886f8f6d4c41177dd91cdb275f0cda6cd9dde93269
Successfully built pyinstaller
Installing collected packages: altgraph, macholib, pyinstaller-hooks-contrib, pyinstaller
Successfully installed altgraph-0.17 macholib-1.14 pyinstaller-4.0.dev0 pyinstaller-hooks-contrib-2020.6
WARNING: You are using pip version 19.2.3, however version 20.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
4.0.dev0
42 INFO: PyInstaller: 4.0.dev0
42 INFO: Python: 3.7.7
49 INFO: Platform: Darwin-18.7.0-x86_64-i386-64bit
50 INFO: wrote /Users/andrewr/Projects/pyinstaller-poc/mac-test/main.spec
53 INFO: UPX is not available.
55 INFO: Extending PYTHONPATH with paths
['/Users/andrewr/Projects/pyinstaller-poc/mac-test',
 '/Users/andrewr/Projects/pyinstaller-poc/mac-test']
60 INFO: checking Analysis
60 INFO: Building Analysis because Analysis-00.toc is non existent
60 INFO: Initializing module dependency graph...
61 INFO: Caching module graph hooks...
68 INFO: Analyzing base_library.zip ...
1761 INFO: Processing pre-find module path hook distutils from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
1762 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7'
2784 INFO: Caching module dependency graph...
2874 INFO: running Analysis Analysis-00.toc
2880 INFO: Analyzing /Users/andrewr/Projects/pyinstaller-poc/mac-test/main.py
2881 INFO: Processing module hooks...
2882 INFO: Loading module hook 'hook-encodings.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2951 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2966 INFO: Loading module hook 'hook-xml.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
3187 INFO: Loading module hook 'hook-distutils.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
3198 INFO: Looking for ctypes DLLs
3198 INFO: Analyzing run-time hooks ...
3206 INFO: Looking for dynamic libraries
3271 INFO: Looking for eggs
3271 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.7/Python
3273 INFO: Warnings written to /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/warn-main.txt
3294 INFO: Graph cross-reference written to /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/xref-main.html
3308 INFO: checking PYZ
3308 INFO: Building PYZ because PYZ-00.toc is non existent
3308 INFO: Building PYZ (ZlibArchive) /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/PYZ-00.pyz
3594 INFO: Building PYZ (ZlibArchive) /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/PYZ-00.pyz completed successfully.
3599 INFO: checking PKG
3599 INFO: Building PKG because PKG-00.toc is non existent
3599 INFO: Building PKG (CArchive) PKG-00.pkg
3605 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
3606 INFO: Bootloader /Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
3606 INFO: checking EXE
3606 INFO: Building EXE because EXE-00.toc is non existent
3606 INFO: Building EXE from EXE-00.toc
3606 INFO: Appending archive to EXE /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/main
3608 INFO: Fixing EXE for code signing /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/main
3611 INFO: Building EXE from EXE-00.toc completed successfully.
3612 INFO: checking COLLECT
3612 INFO: Building COLLECT because COLLECT-00.toc is non existent
3613 INFO: Building COLLECT COLLECT-00.toc
4086 INFO: Building COLLECT COLLECT-00.toc completed successfully.
[10077] Error loading Python lib '/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python': dlopen: dlopen(/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python, 10): no suitable image found.  Did find:
        /Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python: code signature invalid for '/Users/andrewr/Projects/pyinstaller-poc/mac-test/dist/main/Python'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions