简体   繁体   English

使用 pyinstaller 和 python3 为 mac os 创建通用构建

[英]Creating universal build for mac os with pyinstaller and python3

I have two mac machines.我有两台mac机器。 One is intel based and running big sur and second is M1 and running big sur.一个基于英特尔并运行 big sur,第二个是 M1 并运行 big sur。 I am trying to build a sample hello world package using pyinstaller and with universal2 options.我正在尝试使用 pyinstaller 和 universal2 选项构建示例 hello world package。 the package works fine on intel machine but when I copy that package on the M1 machine it throws below error package 在英特尔机器上工作正常但是当我在 M1 机器上复制 package 时它抛出以下错误

marwa@admins-Mac-mini test_app % ls
build           dist            test.py         test.spec
marwa@admins-Mac-mini test_app % cd dist
marwa@admins-Mac-mini dist % ls
test            test.app
marwa@admins-Mac-mini dist % cd test
marwa@admins-Mac-mini test % ls
Python                  libbz2.1.0.dylib        libexpat.1.dylib        libintl.8.dylib         libssl.3.dylib
base_library.zip        libcrypto.3.dylib       libffi.8.dylib          liblzma.5.dylib         libz.1.dylib
lib-dynload             libedit.0.dylib         libiconv.2.dylib        libncurses.6.dylib      test
marwa@admins-Mac-mini test % ./test
[29040] Module object for struct is NULL!
Traceback (most recent call last):
  File "struct.py", line 13, in <module>
ImportError: dynamic module does not define module export function (PyInit__struct)
[29040] Module object for pyimod02_archive is NULL!
Traceback (most recent call last):
  File "PyInstaller/loader/pyimod02_archive.py", line 27, in <module>
ModuleNotFoundError: No module named 'struct'
[29040] Module object for pyimod03_importers is NULL!
Traceback (most recent call last):
  File "PyInstaller/loader/pyimod03_importers.py", line 23, in <module>
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
  File "PyInstaller/loader/pyiboot01_bootstrap.py", line 17, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[29040] Failed to execute script 'pyiboot01_bootstrap' due to unhandled exception: No module named 'pyimod03_importers'
[29040] Traceback:

Compiling my code using below command使用以下命令编译我的代码

cloudqa@MACBOOKAIR01 test_app % /opt/local/bin/python3.9 /opt/local/Library/Frameworks/Python.framework/Versions/3.9/bin/pyinstaller   --target-architecture universal2 test.py

also


cloudqa@MACBOOKAIR01 test_app % lipo -archs /opt/local/bin/python3.9
x86_64 arm64
cloudqa@MACBOOKAIR01 test_app %

If I go and check the architecture of the binary in the dist folder I can see below如果我输入 go 并检查 dist 文件夹中二进制文件的架构,我可以在下面看到

cloudqa@MACBOOKAIR01 test % ls
Python                  libbz2.1.0.dylib        libexpat.1.dylib        libintl.8.dylib         libssl.3.dylib
base_library.zip        libcrypto.3.dylib       libffi.8.dylib          liblzma.5.dylib         libz.1.dylib
lib-dynload             libedit.0.dylib         libiconv.2.dylib        libncurses.6.dylib      test
cloudqa@MACBOOKAIR01 test % lipo -archs test
x86_64 arm64
cloudqa@MACBOOKAIR01 test %

It seems like there is a possible import/path problem early on from where the following errors cascade from.似乎早期可能存在导入/路径问题,从那里级联以下错误。 It's difficult to tell without seeing the code from struct.py.不看 struct.py 中的代码就很难分辨。 Just going by ImportError something is either missing or not properly set.只是通过 ImportError 缺少或未正确设置的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM