Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
arosiclair opened this issue Aug 6, 2020 · 22 comments · Fixed by #5451
Closed
5 tasks done

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

arosiclair opened this issue Aug 6, 2020 · 22 comments · Fixed by #5451
Assignees

Comments

@arosiclair
Copy link

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'
@Legorooj
Copy link
Member

Legorooj commented Aug 6, 2020

@reritom @amifunny can you take a look at this?

@reritom
Copy link

reritom commented Aug 7, 2020

@Legorooj I can have a look over the coming days

@reritom
Copy link

reritom commented Aug 8, 2020

From my first look, I haven't managed to recreate your problem so far.
Some differences are:

  • I'm on Darwin-19.5, while you are Darwin-18.7
  • distutils: retargeting to non-venv dir "..." target different sources (so we are using different Python installations)
Python 3.7.7
pip 19.2.3 from /Users/tom/projects/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: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Requirement already satisfied: setuptools in ./.venv/lib/python3.7/site-packages (from pyinstaller==4.0.dev0) (41.2.0)
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 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 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
Building wheels for collected packages: pyinstaller
  Building wheel for pyinstaller (PEP 517): started
  Building wheel for pyinstaller (PEP 517): finished with status 'done'
  Created wheel for pyinstaller: filename=pyinstaller-4.0.dev0-cp37-none-any.whl size=2804844 sha256=aee3894e318492a864cba027eb8225048051bdd241b0ecba27ad6a728e80a395
  Stored in directory: /private/var/folders/rn/3xcs8df13mjb58n4fzsddndh0000gn/T/pip-ephem-wheel-cache-w7n86ykq/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
4.0.dev0
166 INFO: PyInstaller: 4.0.dev0
166 INFO: Python: 3.7.7
178 INFO: Platform: Darwin-19.5.0-x86_64-i386-64bit
179 INFO: wrote /Users/tom/projects/mac-test/main.spec
184 INFO: UPX is not available.
186 INFO: Extending PYTHONPATH with paths
['/Users/tom/projects/mac-test', '/Users/tom/projects/mac-test']
196 INFO: checking Analysis
196 INFO: Building Analysis because Analysis-00.toc is non existent
196 INFO: Initializing module dependency graph...
199 INFO: Caching module graph hooks...
228 INFO: Analyzing base_library.zip ...
4373 INFO: Processing pre-find module path hook distutils from '/Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
4376 INFO: distutils: retargeting to non-venv dir '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7'
7325 INFO: Caching module dependency graph...
7757 INFO: running Analysis Analysis-00.toc
7778 INFO: Analyzing /Users/tom/projects/mac-test/main.py
7782 INFO: Processing module hooks...
7784 INFO: Loading module hook 'hook-encodings.py' from '/Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
7923 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
7940 INFO: Loading module hook 'hook-xml.py' from '/Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
8455 INFO: Loading module hook 'hook-distutils.py' from '/Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
8514 INFO: Looking for ctypes DLLs
8515 INFO: Analyzing run-time hooks ...
8542 INFO: Looking for dynamic libraries
8806 INFO: Looking for eggs
8806 INFO: Using Python library /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Python
8810 INFO: Warnings written to /Users/tom/projects/mac-test/build/main/warn-main.txt
8862 INFO: Graph cross-reference written to /Users/tom/projects/mac-test/build/main/xref-main.html
8900 INFO: checking PYZ
8900 INFO: Building PYZ because PYZ-00.toc is non existent
8900 INFO: Building PYZ (ZlibArchive) /Users/tom/projects/mac-test/build/main/PYZ-00.pyz
9726 INFO: Building PYZ (ZlibArchive) /Users/tom/projects/mac-test/build/main/PYZ-00.pyz completed successfully.
9744 INFO: checking PKG
9744 INFO: Building PKG because PKG-00.toc is non existent
9746 INFO: Building PKG (CArchive) PKG-00.pkg
9795 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
9797 INFO: Bootloader /Users/tom/projects/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
9798 INFO: checking EXE
9798 INFO: Building EXE because EXE-00.toc is non existent
9799 INFO: Building EXE from EXE-00.toc
9800 INFO: Appending archive to EXE /Users/tom/projects/mac-test/build/main/main
9806 INFO: Fixing EXE for code signing /Users/tom/projects/mac-test/build/main/main
9816 INFO: Building EXE from EXE-00.toc completed successfully.
9818 INFO: checking COLLECT
9818 INFO: Building COLLECT because COLLECT-00.toc is non existent
9819 INFO: Building COLLECT COLLECT-00.toc
10994 INFO: Building COLLECT COLLECT-00.toc completed successfully.
hello, mac

I will continue to look into it.

@reritom
Copy link

reritom commented Aug 8, 2020

@Legorooj
Copy link
Member

@arosiclair pinging

@Legorooj Legorooj added the state:stale by author About to be colosed due to inactivity label Aug 16, 2020
@arosiclair
Copy link
Author

Upgraded to Catalina macOS 10.15.6 but running the excutable still produces the same error:

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 altgraph (from pyinstaller==4.1.dev0)
  Using cached https://files.pythonhosted.org/packages/ee/3d/bfca21174b162f6ce674953f1b7a640c1498357fa6184776029557c25399/altgraph-0.17-py2.py3-none-any.whl
Requirement already satisfied: setuptools in ./.venv/lib/python3.7/site-packages (from pyinstaller==4.1.dev0) (41.2.0)
Collecting pyinstaller-hooks-contrib>=2020.6 (from pyinstaller==4.1.dev0)
  Using cached https://files.pythonhosted.org/packages/22/7a/5dedbe4bc1d5f3f3cf8a3e67abe9896f2a6b6b67f749cba73d9f427320ea/pyinstaller_hooks_contrib-2020.7-py2.py3-none-any.whl
Collecting macholib>=1.8; sys_platform == "darwin" (from pyinstaller==4.1.dev0)
  Using cached https://files.pythonhosted.org/packages/3c/e1/c12f8d6af5d745ce88f270aeb243cb2bd6d8186320e5122df87fded29e4e/macholib-1.14-py2.py3-none-any.whl
Building wheels for collected packages: pyinstaller
  Building wheel for pyinstaller (PEP 517) ... done
  Created wheel for pyinstaller: filename=pyinstaller-4.1.dev0-cp37-none-any.whl size=2789485 sha256=17b10b0e897a285211a5fed604c769764d737347c53f63beac293e1b2dfa3740
  Stored in directory: /private/var/folders/mm/lv7xny1n2nq8f2jw_8zz58qmkkgczp/T/pip-ephem-wheel-cache-qbsx3wkb/wheels/1e/5b/0a/b7b241e8886f8f6d4c41177dd91cdb275f0cda6cd9dde93269
Successfully built pyinstaller
Installing collected packages: altgraph, pyinstaller-hooks-contrib, macholib, pyinstaller
Successfully installed altgraph-0.17 macholib-1.14 pyinstaller-4.1.dev0 pyinstaller-hooks-contrib-2020.7
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
4.1.dev0
39 INFO: PyInstaller: 4.1.dev0
39 INFO: Python: 3.7.7
47 INFO: Platform: Darwin-19.6.0-x86_64-i386-64bit
48 INFO: wrote /Users/andrewr/Projects/pyinstaller-poc/mac-test/main.spec
52 INFO: UPX is not available.
54 INFO: Extending PYTHONPATH with paths
['/Users/andrewr/Projects/pyinstaller-poc/mac-test',
 '/Users/andrewr/Projects/pyinstaller-poc/mac-test']
61 INFO: checking Analysis
61 INFO: Building Analysis because Analysis-00.toc is non existent
61 INFO: Initializing module dependency graph...
63 INFO: Caching module graph hooks...
72 INFO: Analyzing base_library.zip ...
1575 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'.
1575 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7'
2504 INFO: Caching module dependency graph...
2584 INFO: running Analysis Analysis-00.toc
2591 INFO: Analyzing /Users/andrewr/Projects/pyinstaller-poc/mac-test/main.py
2593 INFO: Processing module hooks...
2594 INFO: Loading module hook 'hook-encodings.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2677 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2693 INFO: Loading module hook 'hook-xml.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2937 INFO: Loading module hook 'hook-distutils.py' from '/Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/hooks'...
2948 INFO: Looking for ctypes DLLs
2948 INFO: Analyzing run-time hooks ...
2954 INFO: Looking for dynamic libraries
3037 INFO: Looking for eggs
3037 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.7/Python
3039 INFO: Warnings written to /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/warn-main.txt
3062 INFO: Graph cross-reference written to /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/xref-main.html
3077 INFO: checking PYZ
3077 INFO: Building PYZ because PYZ-00.toc is non existent
3077 INFO: Building PYZ (ZlibArchive) /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/PYZ-00.pyz
3377 INFO: Building PYZ (ZlibArchive) /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/PYZ-00.pyz completed successfully.
3381 INFO: checking PKG
3381 INFO: Building PKG because PKG-00.toc is non existent
3381 INFO: Building PKG (CArchive) PKG-00.pkg
3387 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
3388 INFO: Bootloader /Users/andrewr/Projects/pyinstaller-poc/mac-test/.venv/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
3388 INFO: checking EXE
3388 INFO: Building EXE because EXE-00.toc is non existent
3388 INFO: Building EXE from EXE-00.toc
3389 INFO: Appending archive to EXE /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/main
3390 INFO: Fixing EXE for code signing /Users/andrewr/Projects/pyinstaller-poc/mac-test/build/main/main
3392 INFO: Building EXE from EXE-00.toc completed successfully.
3394 INFO: checking COLLECT
3394 INFO: Building COLLECT because COLLECT-00.toc is non existent
3395 INFO: Building COLLECT COLLECT-00.toc
3860 INFO: Building COLLECT COLLECT-00.toc completed successfully.
[2904] 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'

Not familiar with code signing but this is the error the CLI reports for the binary in question:

codesign --verify --verbose mac-test/dist/main/Python 
mac-test/dist/main/Python: invalid Info.plist (plist or signature have been modified)
In architecture: x86_64

@reritom
Copy link

reritom commented Aug 18, 2020

To me this seems to resemble this open issue #2439

@Legorooj Legorooj added platform:OS X and removed state:stale by author About to be colosed due to inactivity labels Aug 19, 2020
@Legorooj
Copy link
Member

Try adding the --deep option - that can help sometimes.

@ghalter
Copy link

ghalter commented Aug 21, 2020

I just tested @arosiclair 's code, because I have the same error with another application.
Indeed I can reproduce his error:

Python 3.8.5
pip 20.1.1 from /Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/pip (python 3.8)
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"
  Using cached macholib-1.14-py2.py3-none-any.whl (37 kB)
Collecting pyinstaller-hooks-contrib>=2020.6
  Using cached pyinstaller_hooks_contrib-2020.7-py2.py3-none-any.whl (152 kB)
Collecting altgraph
  Using cached altgraph-0.17-py2.py3-none-any.whl (21 kB)
Requirement already satisfied: setuptools in ./.venv/lib/python3.8/site-packages (from pyinstaller==4.1.dev0) (47.1.0)
Building wheels for collected packages: pyinstaller
  Building wheel for pyinstaller (PEP 517) ... done
  Created wheel for pyinstaller: filename=pyinstaller-4.1.dev0-py3-none-any.whl size=2789448 sha256=f0b530b0cc65d0ed0a6bac67c17529360c1f5f1ffae6d970a3d581dead5afa89
  Stored in directory: /private/var/folders/49/0mg4yqmd36j9vc1g6fm1869m0000gn/T/pip-ephem-wheel-cache-i2cz113v/wheels/90/44/63/278e9ab945ca04d7a114732c4aa480ca7bfe887d9b59c74291
Successfully built pyinstaller
Installing collected packages: altgraph, macholib, pyinstaller-hooks-contrib, pyinstaller
Successfully installed altgraph-0.17 macholib-1.14 pyinstaller-4.1.dev0 pyinstaller-hooks-contrib-2020.7
WARNING: You are using pip version 20.1.1; however, version 20.2.2 is available.
You should consider upgrading via the '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/bin/python3 -m pip install --upgrade pip' command.
4.1.dev0
57 INFO: PyInstaller: 4.1.dev0
57 INFO: Python: 3.8.5
64 INFO: Platform: macOS-10.15.5-x86_64-i386-64bit
65 INFO: wrote /Users/Gaudenz/Documents/code/VIAN/test/mac-test/main.spec
68 INFO: UPX is not available.
69 INFO: Extending PYTHONPATH with paths
['/Users/Gaudenz/Documents/code/VIAN/test/mac-test',
 '/Users/Gaudenz/Documents/code/VIAN/test/mac-test']
74 INFO: checking Analysis
74 INFO: Building Analysis because Analysis-00.toc is non existent
74 INFO: Initializing module dependency graph...
76 INFO: Caching module graph hooks...
85 INFO: Analyzing base_library.zip ...
2975 INFO: Processing pre-find module path hook distutils from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
2975 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8'
5543 INFO: Caching module dependency graph...
5686 INFO: running Analysis Analysis-00.toc
5693 INFO: Analyzing /Users/Gaudenz/Documents/code/VIAN/test/mac-test/main.py
5695 INFO: Processing module hooks...
5695 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5696 INFO: Loading module hook 'hook-lib2to3.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5745 INFO: Loading module hook 'hook-_tkinter.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5748 ERROR: Tcl/Tk improperly installed on this system.
5748 INFO: Loading module hook 'hook-encodings.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5815 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5828 INFO: Loading module hook 'hook-xml.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5898 INFO: Loading module hook 'hook-distutils.py' from '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks'...
5920 INFO: Looking for ctypes DLLs
5964 INFO: Analyzing run-time hooks ...
5969 INFO: Including run-time hook '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth__tkinter.py'
5970 INFO: Including run-time hook '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
5980 INFO: Looking for dynamic libraries
6089 INFO: Looking for eggs
6089 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.8/Python
6092 INFO: Warnings written to /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/warn-main.txt
6134 INFO: Graph cross-reference written to /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/xref-main.html
6156 INFO: checking PYZ
6156 INFO: Building PYZ because PYZ-00.toc is non existent
6156 INFO: Building PYZ (ZlibArchive) /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/PYZ-00.pyz
6682 INFO: Building PYZ (ZlibArchive) /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/PYZ-00.pyz completed successfully.
6694 INFO: checking PKG
6694 INFO: Building PKG because PKG-00.toc is non existent
6694 INFO: Building PKG (CArchive) PKG-00.pkg
6703 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6704 INFO: Bootloader /Users/Gaudenz/Documents/code/VIAN/test/mac-test/.venv/lib/python3.8/site-packages/PyInstaller/bootloader/Darwin-64bit/run
6704 INFO: checking EXE
6705 INFO: Building EXE because EXE-00.toc is non existent
6705 INFO: Building EXE from EXE-00.toc
6705 INFO: Appending archive to EXE /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/main
6709 INFO: Fixing EXE for code signing /Users/Gaudenz/Documents/code/VIAN/test/mac-test/build/main/main
6711 INFO: Building EXE from EXE-00.toc completed successfully.
6712 INFO: checking COLLECT
6713 INFO: Building COLLECT because COLLECT-00.toc is non existent
6713 INFO: Building COLLECT COLLECT-00.toc
7670 INFO: Building COLLECT COLLECT-00.toc completed successfully.
[66463] Error loading Python lib '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/dist/main/Python': dlopen: dlopen(/Users/Gaudenz/Documents/code/VIAN/test/mac-test/dist/main/Python, 10): no suitable image found.  Did find:
        /Users/Gaudenz/Documents/code/VIAN/test/mac-test/dist/main/Python: code signature invalid for '/Users/Gaudenz/Documents/code/VIAN/test/mac-test/dist/main/Python'

I then followed this recipe to add a code-sign (using the deep argument) Recipe OSX Code Signing.

  1. I created a self signed certificate for "Sandbox"
  2. I added following code to the spec file:
app = BUNDLE(exe,
         name='Sandbox.app',
         icon=None,
         bundle_identifier=None,
         info_plist={
            'NSPrincipalClass': 'NSApplication',
            'NSAppleScriptEnabled': False,
            'CFBundleDocumentTypes': [
                {
                    'LSItemContentTypes': ['com.example.myformat'],
                    'LSHandlerRank': 'Owner'
                    }
                ]
            },
         )
  1. Finally I called codesign -s "Sandbox" --deep dist/sandbox.app
    Yet, I still get the same error.

@vsalvino
Copy link

vsalvino commented Aug 31, 2020

I am also hitting this issue. I have traced it down to the fact that executables built in onefile mode with Python 3.7.6 work correctly, but built with any higher version of Python (3.7.7, 3.7.8, 3.7.9) does not work and throws the invalid code signature error. I have confirmed this by building with multiple version on a mac with OS 10.15.6. I also tried multiple versions of PyInstaller 3.5, 3.6, 4.0 all yielding the same results.

Found this thread which was very helpful: http://pyinstaller.47505.x6.nabble.com/Help-needed-Error-loading-Python-lib-td2872.html#a2873

@rokm
Copy link
Member

rokm commented Aug 31, 2020

From 3.7.7 on and from 3.8.2 on, the macOS installer packages from python.org are compatible with Gatekeeper requirements regarding code signing.

The Python library file is now signed, and moving it invalidates the signature, e.g.:

$ codesign --verify --verbose dist/hello/Python 
dist/hello/Python: invalid Info.plist (plist or signature have been modified)
In architecture: x86_64

This in turn causes the Error loading Python lib.

A possible work-around may be removing the signature from Python library file.

$ codesign --remove-signature dist/hello/Python

This seems to do the trick for a onedir application. Perhaps the signature needs to be stripped from Python before/while creating the bundle as well.

@marticliment
Copy link

marticliment commented Sep 12, 2020

I just downgraded from Python 3.7.7 to Python 3.7.6. I don't know the reason, but as @rokm said, I guess this is related to the recent addition of full Gatekeeper notarization on macOS binaries, (read on the changelog https://www.python.org/downloads/release/python-379/) On the macOS section, is wrote this: As of 3.7.7, macOS installer packages are now compatible with the full Gatekeeper notarization requirements of macOS 10.15 Catalina including code signing
I guess that because on windows and on Ubuntu PyInstaller and Python 3.7.7-3.7.9 are working fine, but on macOS it is not working since Python 3.7.7, the first version to have this new "Feature"

After reading this, I tested with homebrew python version and also didn't work ☹

@nicozanf
Copy link

nicozanf commented Dec 6, 2020

I can confirm this behaviour and the workaround.
My app was working fine with Python 3.7.4 and PyInstaller 3.9/4.0. Now I've found that it gives that error if compiled with Python 3.8.6 and PyInstaller 4.1/4.1dev on MacOs 10.12.6 or 10.15.4. But after running on it:

$ sudo codesign --remove-signature Python

it works fine again (without having to sign anything)!

@dsoegijono
Copy link

dsoegijono commented Jan 21, 2021

I still have this issue even after downgrading to python 3.7.6 or using python 3.9.1, on MacOS 11.1

It seems to work on the mac that generates the app, but the dist doesn't work on any other mac machine.

Error on usage:

$ myscript
[60786] Error loading Python lib '/var/folders/yq/1y1vcbld4sz5t00d3qctmsc80000gn/T/_MEIncCe0Z/Python': dlopen: dlopen(/var/folders/yq/1y1vcbld4sz5t00d3qctmsc80000gn/T/_MEIncCe0Z/Python, 10): Symbol not found: _preadv
  Referenced from: /var/folders/yq/1y1vcbld4sz5t00d3qctmsc80000gn/T/_MEIncCe0Z/Python (which was built for Mac OS X 11.1)
  Expected in: /usr/lib/libSystem.B.dylib
 in /var/folders/yq/1y1vcbld4sz5t00d3qctmsc80000gn/T/_MEIncCe0Z/Python

@rokm
Copy link
Member

rokm commented Jan 21, 2021

@dsoegijono If you take a closer look at your error message, you'll see that it's a different issue. You are using python that was build with minimum macOS version set to 11.1, so the Python shared library collected from that will not load on any earlier version of macOS.

I suppose you are using a custom python build, because official python.org builds have minimum version still set to 10.9 (even the new macos11 variant of python 3.9.1).

@dsoegijono
Copy link

dsoegijono commented Jan 21, 2021

Thanks @rokm would it be better if I create a separate issue then? I'm not sure why the minimum version is set to 11.1

I suppose you are using a custom python build, because official python.org builds have minimum version still set to 10.9 (even the new macos11 variant of python 3.9.1).

I installed via pyenv

 pyenv install 3.9.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.1.tar.xz...
-> https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
Installing Python-3.9.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.1 to /Users/daphne/.pyenv/versions/3.9.1

@rokm
Copy link
Member

rokm commented Jan 21, 2021

That pyenv command seems to build python from source, and the minimum target macOS version is probably the default that comes from your OS version and/or installed XCode version.

I've no idea how much you can influence it from pyenv, though - I imagine that for pyenv and brew, cross-version compatibility is not really a concern, as you are always building/installing the version that matches the local OS version. (As a side note, the 3.9.1 python bottles in homebrew seem to have minimum version set to their corresponding bottle name, as well). It does mean that PyInstaller-frozen programs built with that version of python won't work on older macOS versions, though.

So either you'll need to switch to python version that's backwards compatible (like python.org builds), or use an older version of macOS as your build system.

@BoboTiG
Copy link
Contributor

BoboTiG commented Jan 21, 2021

Maybe setting the MACOSX_DEPLOYMENT_TARGET envar could influence how pyenv builds Python.

@dofamin-1
Copy link

Hi there

I have a similar problem, but not the same.
My executable (--onefile) is working fine but after signing it I started getting this error message:

[61623] Error loading Python lib '/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python': dlopen: dlopen(/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python, 0x000A): tried: '/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python' (code signature in <D264938F-83FF-32D7-A48C-32BE5E18DEE9> '/private/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/private/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python' (code signature in <D264938F-83FF-32D7-A48C-32BE5E18DEE9> '/private/var/folders/1_/nz8m7dbx24d9_4bkng58vlqw0000gn/T/_MEIXqq3is/Python' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))

Has anyone else come across this problem too?
Will be glad for any feedback.

@rokm
Copy link
Member

rokm commented Sep 22, 2022

Manually signing onefile binaries post-hoc with codesign is unlikely to work, because it signs only the executable itself. It does not (and cannot) sign the embedded binaries, like the python shared library in your error message. You can try to enable signing with your codesign identity during the build with --codesign-identity; if that does not help, you'll have to switch to onedir build.

@dofamin-1
Copy link

dofamin-1 commented Sep 22, 2022

Thank you for quick response @rokm !
Well if I decide to switch to onedir build, how should I codesign that folder (which contains all stuff created by PyInstaller (with --onedir option)).
Note: I am signing using the command line (Not with XCode)

@rokm
Copy link
Member

rokm commented Sep 22, 2022

You can (re)sign problematic files one by one, you can try listing them based on extension (.dylib and .so), you could read build/<name>/Analysis-00.toc to obtain list of BINARY and EXTENSION entries. I don't imagine any of these approaches to be 100% successful, though, so you'll still be in for some manual work.

Depending on your application type (i.e., if it is not pure CLI program), you could instead try generating .app bundle and sign that recursively using codesign --force --deep ....

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.