Repository: pyinstaller/pyinstaller

Issue:
code sign issue on OS X when compiling using --onefile  
No found combination of PyInstaller and Python seems to be able to resolve the following error:

`[2813] LOADER: Python library: /var/folders/y_/ny7yy6g97kq5mn8p7wxnry640000gq/T/_MEImSTwzT/Python
[2813] Error loading Python lib '/var/folders/y_/ny7yy6g97kq5mn8p7wxnry640000gq/T/_MEImSTwzT/Python': dlopen: dlopen(/var/folders/y_/ny7yy6g97kq5mn8p7wxnry640000gq/T/_MEImSTwzT/Python, 10): no suitable image found.  Did find:
	/var/folders/y_/ny7yy6g97kq5mn8p7wxnry640000gq/T/_MEImSTwzT/Python: code signature invalid for '/var/folders/y_/ny7yy6g97kq5mn8p7wxnry640000gq/T/_MEImSTwzT/Python'
`

The ONLY resolution I can find for the issue is to compile using --onedir and then navigate to the dist folder and issue the `sudo codesign --remove-signature Python` command mentioned in issue 5062.  --onefile mode will not function with any combination of PyInstaller or Python versions I have found including the latest developer version, or brew installations.  Also, multiple attempts have been made to use Mac's codesign utility in --onefile mode to resolve the issue with no positive results.  

Reference Issues: 5272 and 5062 below:
[https://github.com/pyinstaller/pyinstaller/issues/5272](url)
[https://github.com/pyinstaller/pyinstaller/issues/5062](url)

Might it be possible to provide a switch to bundle an unsigned Python with the --onefile option?

Compiler Trace:
`151 INFO: PyInstaller: 4.2.dev0
151 INFO: Python: 3.9.1
172 INFO: Platform: macOS-10.16-x86_64-i386-64bit
188 INFO: UPX is not available.
190 INFO: Extending PYTHONPATH with paths
['/Users/James/Documents/Python_Code/Blastro_Mac',
 '/Users/snizbatch/Documents/Python Code/Blastro_Mac']
199 INFO: checking Analysis
199 INFO: Building Analysis because Analysis-00.toc is non existent
199 INFO: Initializing module dependency graph...
231 INFO: Caching module graph hooks...
239 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
257 INFO: Analyzing base_library.zip ...
7955 INFO: Processing pre-find module path hook distutils from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
7956 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9'
9811 INFO: Caching module dependency graph...
9894 INFO: running Analysis Analysis-00.toc
9897 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9)
9899 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/Python)
9899 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/Python)
9899 INFO: Analyzing blastro.py
10477 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-urllib3.packages.six.moves.py'.
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/firefox/firefox_profile.py:208: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if setting is None or setting is '':
13985 INFO: Processing module hooks...
13985 INFO: Loading module hook 'hook-selenium.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
14044 INFO: Loading module hook 'hook-certifi.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
14046 INFO: Loading module hook 'hook-Crypto.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
14050 INFO: Loading module hook 'hook-openpyxl.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
14114 INFO: Loading module hook 'hook-pkg_resources.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14308 INFO: Processing pre-safe import module hook win32com from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'.
14456 WARNING: Hidden import "pkg_resources.py2_warn" not found!
14456 WARNING: Hidden import "pkg_resources.markers" not found!
14458 INFO: Excluding import of __main__ from module pkg_resources
14459 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14459 INFO: Loading module hook 'hook-pytz.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14533 INFO: Loading module hook 'hook-lib2to3.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14565 INFO: Loading module hook 'hook-_tkinter.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14567 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_tkinter.cpython-39-darwin.so)
14654 INFO: checking Tree
14654 INFO: Building Tree because Tree-00.toc is non existent
14654 INFO: Building Tree Tree-00.toc
14682 INFO: checking Tree
14682 INFO: Building Tree because Tree-01.toc is non existent
14682 INFO: Building Tree Tree-01.toc
14733 INFO: checking Tree
14733 INFO: Building Tree because Tree-02.toc is non existent
14733 INFO: Building Tree Tree-02.toc
14736 INFO: Loading module hook 'hook-encodings.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14809 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14815 INFO: Excluding import of numpy from module PIL.ImageFilter
14815 INFO: Loading module hook 'hook-distutils.util.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14816 INFO: Excluding import of lib2to3.refactor from module distutils.util
14817 INFO: Loading module hook 'hook-PIL.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14818 INFO: Import to be excluded not found: 'FixTk'
14820 INFO: Excluding import of tkinter from module PIL.ImageTk
14822 INFO: Excluding import of PyQt5 from module PIL.ImageQt
14822 INFO: Loading module hook 'hook-xml.dom.domreg.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
14823 INFO: Loading module hook 'hook-PIL.Image.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15080 INFO: Loading module hook 'hook-pickle.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15085 INFO: Excluding import of argparse from module pickle
15085 INFO: Loading module hook 'hook-heapq.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15088 INFO: Excluding import of doctest from module heapq
15088 INFO: Loading module hook 'hook-difflib.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15091 INFO: Excluding import of doctest from module difflib
15091 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15094 INFO: Excluding import of test from module multiprocessing.util
15094 INFO: Excluding import of test.support from module multiprocessing.util
15094 INFO: Loading module hook 'hook-sysconfig.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15103 INFO: Loading module hook 'hook-xml.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15104 INFO: Loading module hook 'hook-distutils.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15107 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks'...
15109 INFO: Import to be excluded not found: 'FixTk'
15145 INFO: Looking for ctypes DLLs
15240 INFO: Analyzing run-time hooks ...
15245 INFO: Including run-time hook '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_pyinstaller_hooks_contrib/hooks/rthooks/pyi_rth_certifi.py'
15246 INFO: Including run-time hook '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth__tkinter.py'
15247 INFO: Including run-time hook '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
15249 INFO: Including run-time hook '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgres.py'
15263 INFO: Looking for dynamic libraries
15265 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_SHA1.cpython-39-darwin.so)
15267 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_eksblowfish.cpython-39-darwin.so)
15268 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_blowfish.cpython-39-darwin.so)
15270 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_RIPEMD160.cpython-39-darwin.so)
15272 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_BLAKE2b.cpython-39-darwin.so)
15274 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_BLAKE2s.cpython-39-darwin.so)
15276 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_MD2.cpython-39-darwin.so)
15277 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_SHA256.cpython-39-darwin.so)
15279 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_SHA384.cpython-39-darwin.so)
15280 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_ctr.cpython-39-darwin.so)
15282 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_SHA224.cpython-39-darwin.so)
15284 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_poly1305.cpython-39-darwin.so)
15287 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_SHA512.cpython-39-darwin.so)
15290 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_ofb.cpython-39-darwin.so)
15292 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Util/_strxor.cpython-39-darwin.so)
15295 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_des.cpython-39-darwin.so)
15298 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/PublicKey/_ec_ws.cpython-39-darwin.so)
15300 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_arc2.cpython-39-darwin.so)
15303 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_ARC4.cpython-39-darwin.so)
15305 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_keccak.cpython-39-darwin.so)
15309 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_ghash_portable.cpython-39-darwin.so)
15313 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_cast.cpython-39-darwin.so)
15315 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_cbc.cpython-39-darwin.so)
15318 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_aes.cpython-39-darwin.so)
15320 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_cfb.cpython-39-darwin.so)
15322 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_Salsa20.cpython-39-darwin.so)
15324 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.cpython-39-darwin.so)
15327 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_MD4.cpython-39-darwin.so)
15329 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_des3.cpython-39-darwin.so)
15365 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Hash/_MD5.cpython-39-darwin.so)
15368 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_chacha20.cpython-39-darwin.so)
15371 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Protocol/_scrypt.cpython-39-darwin.so)
15374 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Math/_modexp.cpython-39-darwin.so)
15378 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Util/_cpuid_c.cpython-39-darwin.so)
15380 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/Cipher/_raw_ocb.cpython-39-darwin.so)
15384 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_hashlib.cpython-39-darwin.so)
15386 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_sha3.cpython-39-darwin.so)
15387 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_blake2.cpython-39-darwin.so)
15389 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_sha512.cpython-39-darwin.so)
15393 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_sha256.cpython-39-darwin.so)
15397 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_md5.cpython-39-darwin.so)
15398 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_sha1.cpython-39-darwin.so)
15399 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_statistics.cpython-39-darwin.so)
15400 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_contextvars.cpython-39-darwin.so)
15401 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_decimal.cpython-39-darwin.so)
15403 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_random.cpython-39-darwin.so)
15404 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_bisect.cpython-39-darwin.so)
15405 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_uuid.cpython-39-darwin.so)
15406 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_struct.cpython-39-darwin.so)
15407 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/select.cpython-39-darwin.so)
15409 ERROR: Can not find path /usr/lib/libz.1.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/binascii.cpython-39-darwin.so)
15409 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/binascii.cpython-39-darwin.so)
15410 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_ssl.cpython-39-darwin.so)
15412 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/termios.cpython-39-darwin.so)
15414 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/unicodedata.cpython-39-darwin.so)
15415 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/grp.cpython-39-darwin.so)
15416 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_csv.cpython-39-darwin.so)
15418 ERROR: Can not find path /usr/lib/libedit.3.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/readline.cpython-39-darwin.so)
15418 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/readline.cpython-39-darwin.so)
15419 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_opcode.cpython-39-darwin.so)
15420 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/array.cpython-39-darwin.so)
15421 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/pyexpat.cpython-39-darwin.so)
15422 ERROR: Can not find path /usr/lib/libz.1.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/zlib.cpython-39-darwin.so)
15423 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/zlib.cpython-39-darwin.so)
15424 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_posixshmem.cpython-39-darwin.so)
15425 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_multiprocessing.cpython-39-darwin.so)
15426 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_posixsubprocess.cpython-39-darwin.so)
15427 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/mmap.cpython-39-darwin.so)
15429 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_queue.cpython-39-darwin.so)
15430 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_multibytecodec.cpython-39-darwin.so)
15432 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_jp.cpython-39-darwin.so)
15433 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_iso2022.cpython-39-darwin.so)
15434 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_bz2.cpython-39-darwin.so)
15434 ERROR: Can not find path /usr/lib/libbz2.1.0.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_bz2.cpython-39-darwin.so)
15435 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_tw.cpython-39-darwin.so)
15436 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_kr.cpython-39-darwin.so)
15438 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_cn.cpython-39-darwin.so)
15439 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_codecs_hk.cpython-39-darwin.so)
15440 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_heapq.cpython-39-darwin.so)
15441 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_json.cpython-39-darwin.so)
15442 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_tkinter.cpython-39-darwin.so)
15443 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/_imagingtk.cpython-39-darwin.so)
15446 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/_webp.cpython-39-darwin.so)
15448 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so)
15449 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_datetime.cpython-39-darwin.so)
15450 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_asyncio.cpython-39-darwin.so)
15452 ERROR: Can not find path /usr/lib/libffi.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so)
15452 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so)
15453 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/math.cpython-39-darwin.so)
15454 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_elementtree.cpython-39-darwin.so)
15455 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_lzma.cpython-39-darwin.so)
15456 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_scproxy.cpython-39-darwin.so)
15456 ERROR: Can not find path /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_scproxy.cpython-39-darwin.so)
15456 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_scproxy.cpython-39-darwin.so)
15457 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_socket.cpython-39-darwin.so)
15460 ERROR: Can not find path /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/psutil/_psutil_osx.cpython-39-darwin.so)
15460 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/psutil/_psutil_osx.cpython-39-darwin.so)
15461 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/psutil/_psutil_osx.cpython-39-darwin.so)
15463 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/psutil/_psutil_posix.cpython-39-darwin.so)
15465 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/fcntl.cpython-39-darwin.so)
15466 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_curses.cpython-39-darwin.so)
15467 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/resource.cpython-39-darwin.so)
15468 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_pickle.cpython-39-darwin.so)
15470 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libssl.1.1.dylib)
15472 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libcrypto.1.1.dylib)
15473 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libncursesw.5.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /usr/lib/libobjc.A.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /usr/lib/libz.1.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15476 ERROR: Can not find path /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15477 ERROR: Can not find path /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15477 ERROR: Can not find path /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15477 ERROR: Can not find path /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtk8.6.dylib)
15479 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtcl8.6.dylib)
15479 ERROR: Can not find path /usr/lib/libz.1.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtcl8.6.dylib)
15479 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/libtcl8.6.dylib)
15480 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libwebpmux.3.dylib)
15483 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libwebp.7.dylib)
15484 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libwebpdemux.2.dylib)
15485 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libjpeg.9.dylib)
15486 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libopenjp2.2.3.1.dylib)
15487 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libxcb.1.1.0.dylib)
15488 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libz.1.2.11.dylib)
15490 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libtiff.5.dylib)
15492 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/libXau.6.dylib)
15493 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/.dylibs/liblzma.5.dylib)
15494 INFO: Looking for eggs
15494 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.9/Python
15503 INFO: Warnings written to /Users/James/Documents/Python_Code/Blastro_Mac/build/blastro/warn-blastro.txt
15639 INFO: Graph cross-reference written to /Users/James/Documents/Python_Code/Blastro_Mac/build/blastro/xref-blastro.html
15706 INFO: checking Tree
15706 INFO: Building Tree because Tree-03.toc is non existent
15706 INFO: Building Tree Tree-03.toc
15706 INFO: checking Tree
15706 INFO: Building Tree because Tree-04.toc is non existent
15706 INFO: Building Tree Tree-04.toc
15708 INFO: checking PYZ
15708 INFO: Building PYZ because PYZ-00.toc is non existent
15708 INFO: Building PYZ (ZlibArchive) /Users/James/Documents/Python_Code/Blastro_Mac/build/blastro/PYZ-00.pyz
16443 INFO: Building PYZ (ZlibArchive) /Users/James/Documents/Python_Code/Blastro_Mac/build/blastro/PYZ-00.pyz completed successfully.
16462 INFO: checking PKG
16462 INFO: Building PKG because PKG-00.toc is non existent
16462 INFO: Building PKG (CArchive) PKG-00.pkg
17484 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9)
20849 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
20874 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/bootloader/Darwin-64bit/run_d
20874 INFO: checking EXE
20874 INFO: Building EXE because EXE-00.toc is non existent
20875 INFO: Building EXE from EXE-00.toc
20875 INFO: Appending archive to EXE /Users/James/Documents/Python_Code/Blastro_Mac/dist/Blastro
20886 INFO: Fixing EXE for code signing /Users/James/Documents/Python_Code/Blastro_Mac/dist/Blastro
20887 INFO: Building EXE from EXE-00.toc completed successfully.
20911 INFO: checking BUNDLE
20911 INFO: Building BUNDLE because BUNDLE-00.toc is non existent
20911 INFO: Building BUNDLE BUNDLE-00.toc
20922 INFO: moving BUNDLE data files to Resource directory`


Discussion:
Have you tried removing the signature from the original copy of the `Python` shared library file in your build environment (`sudo codesign --remove-signature /Library/Frameworks/Python.framework/Versions/3.9/Python`)? Then it should not matter if you're building with `--onedir` or `--onefile`... (it might, depending on your security settings, affect that python installation, though...)
rokm, I had not done that.  What I was doing was the following:
```
which python3
cd ^^(result from the above command)^^
sudo codesign --remove-signature python3
sudo codesign --remove-signature python3.9
```
So I was INCORRECTLY (backing up and then) removing the signature from the Mac executable rather than the library.

As you mentioned, here was the final solution:
```
cd /Library/Frameworks/Python.framework/Versions/3.9
mkdir backup_exe
cp Python backup_exe
sudo codesign --remove-signature Python
```


Forgive me for not fully understanding where PyInstaller sourced it's python interpreter from.  I assumed that the packaged interpreter would have to be an executable otherwise what would run when the app was executed?  My ignorance.

In any case, your solution does work!  I am not a 'Mac Guy' but have ported my python app to Mac.  The frustrations I've had developing on this platform have been infuriating. Particularly with code signing.  PyInstaller hasn't been without troubles (namely the Tkinter GUI problems) but it has eventually pulled through in creating an app package each time throughout my frustrations.  I will be donating to PyInstaller for keeping me sane!  The persistence of the developers of this package is remarkable!  Thank you all.

Now on to codesigning with MY signature (this should be fun)
Jim


I'm totally with you on the codesigning being a nuisance. It's a shame really. I'd quite like macOS if it weren't for all the cyber bureaucracy they've gummed it up with.

@rokm, @Legorooj Do either of you know if/why we couldn't run this codesign strip signature automatically? i.e. Copy `python.dylib` (or whatever it's called) to the build dir, `codesign --remove-signature Python` it, then put that in either onedir or onefile applications. I understand that codesign has been a standard part of the operating system since the stone age. The only thing I can think of is that it may require `sudo` escalation?
> @rokm, @Legorooj Do either of you know if/why we couldn't run this codesign strip signature automatically?

I suspect we don't do that only because nobody took a stab at it yet. That, and the issue is relatively new (compared to other issues, such as the `tkinter` mess that we had on macOS).

I've been looking around the code earlier today, and I think a good place to add this is before or after the `dylib.mac_set_relative_dylib_deps()` calls in `checkCache()` ([here](https://github.com/pyinstaller/pyinstaller/blob/53b149eb96b88927df1e9728890a26b3895a62d1/PyInstaller/building/utils.py#L224) and [here](https://github.com/pyinstaller/pyinstaller/blob/53b149eb96b88927df1e9728890a26b3895a62d1/PyInstaller/building/utils.py#L358)), to keep all macOS-related voodoo concentrated in one place.

I.e., add a `osx.strip_library_signature()` utility function, which wraps the `codesign` calls to check for the signature and try removing it (or just try removing it, depending on what return codes from `codesign` are like). And maybe do that only for `Python` library for now.

I'll try to come up with a proof-of-concept in the upcoming days...

> The only thing I can think of is that it may require sudo escalation?

No, the escalation is not needed to modify a local copy of the library, so that should not be a problem.
Thank you all for addressing this.  Donation has been sent, and I'm not opposed to sending more to keep this project alive and well.  While on the issue, and I hope I'm not over-stepping any bounds by making this suggestion here, but every app I package receives the 'Apple "XYZ" can't be opened because Apple cannot check it for malicious software.'  even when I've signed the app package (including with --deep and --force.  I have to tell everyone to override it with the "Control-Click open" Which is really uncomfortable to explain to a virus nervous Mac user.  I've read posts on how Apple wants EVERY file inside of the package to be individually signed.  This is nearly impossible for me to fathom doing inside of an .app and beyond my comprehension.  If there is a way to make PyInstaller apply the "bundle_identifier" code signature provided to all the files packaged?  As mentioned before I'm not super knowledgeable on the intricacies of code signing but I'm trying!!  If this is better suited for another thread or simply not feasible, I apologize.

Again, thanks for your time and help!
Jim
Hmm, this falls outside of my expertise, but...

I think what works right now is creating the .app bundle with application frozen in `onedir` mode, and then recursively signing all binaries in the .app bundle (directory) with external script. For example, see https://github.com/pyinstaller/pyinstaller/issues/4934#issuecomment-702131902 or https://github.com/pyinstaller/pyinstaller/pull/3991#issuecomment-586905601.

But I imagine that .app bundles with application frozen in `onefile` mode will run into issues, because the binaries that are embedded into executable (and then extracted into temporary directory when the program is run) are not signed. And since they are embedded in PyInstaller-specific archive/format, there's no easy way to sign them in a post-processing step (the situation is actually very much akin to the issue with stripping the signature off the `Python` library). If I understand correctly, #3991 is aiming to address that, but so far it has not been merged yet.
I am just chiming in to agree with @rokm, I don't think signing an app in onefile mode will work. I think #3991 was aiming to run codesign against a .app bundle, which you can already do manually once PyInstaller has bundled your app with onedir mode.

Resolving patch:
diff --git a/PyInstaller/building/utils.py b/PyInstaller/building/utils.py
--- a/PyInstaller/building/utils.py
+++ b/PyInstaller/building/utils.py
@@ -219,9 +219,11 @@ def checkCache(fnm, strip=False, upx=False, upx_exclude=None, dist_nm=None):
             os.remove(cachedfile)
         else:
             # On Mac OS X we need relative paths to dll dependencies
-            # starting with @executable_path
+            # starting with @executable_path. We may also need to strip
+            # (invalidated) signature from collected shared libraries.
             if is_darwin:
                 dylib.mac_set_relative_dylib_deps(cachedfile, dist_nm)
+                dylib.mac_strip_signature(cachedfile, dist_nm)
             return cachedfile
 
 
@@ -353,9 +355,11 @@ def checkCache(fnm, strip=False, upx=False, upx_exclude=None, dist_nm=None):
     save_py_data_struct(cacheindexfn, cache_index)
 
     # On Mac OS X we need relative paths to dll dependencies
-    # starting with @executable_path
+    # starting with @executable_path. We may also need to strip
+    # (invalidated) signature from collected shared libraries.
     if is_darwin:
         dylib.mac_set_relative_dylib_deps(cachedfile, dist_nm)
+        dylib.mac_strip_signature(cachedfile, dist_nm)
     return cachedfile
 
 
diff --git a/PyInstaller/depend/dylib.py b/PyInstaller/depend/dylib.py
--- a/PyInstaller/depend/dylib.py
+++ b/PyInstaller/depend/dylib.py
@@ -340,3 +340,57 @@ def match_func(pth):
             f.flush()
     except Exception:
         pass
+
+
+def mac_is_binary_signed(filename):
+    """
+    Check if the given macOS binary file is signed.
+    """
+    from macholib.MachO import MachO
+    from macholib import mach_o  # constants
+
+    # Open the file
+    try:
+        m = MachO(filename)
+    except Exception:
+        return False
+
+    # Walk over all headers and check if any contains LC_CODE_SIGNATURE
+    # load command
+    for header in m.headers:
+        for cmd in header.commands:
+            if cmd[0].cmd == mach_o.LC_CODE_SIGNATURE:
+                return True
+    return False
+
+
+def mac_strip_signature(libname, distname):
+    """
+    On macOS, strip away the signature from the binary file. As we may
+    not be collecting all components from a signed framework bundle, the
+    collection may invalidate the existing signature on a collected
+    shared library, which will prevent the latter from being loaded.
+    """
+    from ..compat import exec_command_rc
+
+    # For now, limit this only to Python shared library. Other shared
+    # library files from Python.framework bundle also seem to be signed,
+    # but their signature is not invalidated by partial collection like
+    # it is for Python library...
+    if os.path.basename(libname) != 'Python':
+        return
+    if not mac_is_binary_signed(libname):
+        return
+    # Run codesign --remove-signature libname
+    try:
+        logger.debug("Removing signature from %s", libname)
+        result = exec_command_rc('codesign', '--remove-signature', libname)
+    except Exception as e:
+        logger.warning(
+            "Failed to run 'codesign' to remove signature from %s: %r",
+            libname, e)
+        return
+    if result != 0:
+        logger.warning(
+            "'codesign --remove-signature %s' returned non-zero status %d",
+            libname, result)


Test patch: