When install trying to install pycryptodome with pip, I got the following message.
Firstly, It's CPython problem and not pycryptodome fault because The problem consisted between a few different packages.
Secondly, According to my findings it's a problem in the setuptools package, and more specifically the problem root is in a value inside the sysconfig package.
$ pip3 install pycryptodome
...
Building wheels for collected packages: pycryptodome
Building wheel for pycryptodome (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pycryptodome (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [336 lines of output]
...
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/opt/homebrew/opt/llvm/include -DHAVE_STDINT_H -DPYCRYPTO_LITTLE_ENDIAN -DSYS_BITS=64 -DLTC_NO_ASM -DHAVE_UINT128 -DHAVE_POSIX_MEMALIGN -Isrc/ -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c src/MD2.c -o build/temp.macosx-10.9-universal2-cpython-311/src/MD2.o
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g -L/opt/homebrew/opt/llvm/lib -I/opt/homebrew/opt/llvm/include build/temp.macosx-10.9-universal2-cpython-311/src/MD2.o -o build/lib.macosx-10.9-universal2-cpython-311/Crypto/Hash/_MD2.abi3.so
ld: warning: dylib (/opt/homebrew/opt/llvm/lib/libunwind.dylib) was built for newer macOS version (13.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/opt/llvm/lib/libunwind.dylib) was built for newer macOS version (13.0) than being linked (11.0)
ld: in'/opt/homebrew/opt/llvm/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
error: command'/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pycryptodome
Failed to build pycryptodome
ERROR: Could not build wheels for pycryptodome, which is required to install pyproject.toml-based projects
Note that there is both a -arch x86_64 and a -arch arm64, this caused the linker to error because the compiled file and the library file where from different architectures.
The cause for this is that CFLAGS (and LDFLAGS) variables are containing both -arch arm64 and -arch x86_64.
To stop the problem from occurring in the future it is needed to figure out why _sysconfigdata__darwin_darwin.py
contained those flags in the first place (Maybe also remove the -g debug flag).
Because I wasn't able to recreate the problem when compiling cpython from source.
I think it's due to the way the macos package was compiled.
One more possible fix is to add some code that detect if there are multiple -arch flags and remove them.
My environment
CPython versions tested on: 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)]
Operating system and architecture: Darwin Macbook-Pro 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64
Temporary Fix
A temporary fix to the problem is to set the ARCHFLAGS environment variable.
$ export ARCHFLAGS='-arch arm64'
Or modify the configuration directly, by modify the python package internal files. On my specific machine the file is /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/_sysconfigdata__darwin_darwin.py
The text was updated successfully, but these errors were encountered:
Note that this is not a bug in CPython, but an incompatibility in your environment. The installer on www.python.org ships as a "Universal 2" binary supporting both arm64 and x86_64. Homebrew apparently only installs binaries targeting the current machine, which in your case means that it only supports arm64. This is what causes the link error, and that's not something we can fix on the CPython end.
BTW. You could consider to ask the pycryptodome maintainers if they are willing to ship arm64 or (IMHO preferably) universal2 wheels, they appear to use the "cibuildwheel" project to build wheels and project also supports building wheels supporting arm64.
galchapman commentedDec 22, 2022
•
edited
Bug report
When install trying to install pycryptodome with pip, I got the following message.
Firstly, It's CPython problem and not pycryptodome fault because The problem consisted between a few different packages.
Secondly, According to my findings it's a problem in the
setuptools
package, and more specifically the problem root is in a value inside thesysconfig
package.Note that there is both a
-arch x86_64
and a-arch arm64
, this caused the linker to error because the compiled file and the library file where from different architectures.The cause for this is that CFLAGS (and LDFLAGS) variables are containing both
-arch arm64
and-arch x86_64
.To stop the problem from occurring in the future it is needed to figure out why
_sysconfigdata__darwin_darwin.py
contained those flags in the first place (Maybe also remove the
-g
debug flag).Because I wasn't able to recreate the problem when compiling cpython from source.
I think it's due to the way the macos package was compiled.
One more possible fix is to add some code that detect if there are multiple
-arch
flags and remove them.My environment
Temporary Fix
A temporary fix to the problem is to set the ARCHFLAGS environment variable.
Or modify the configuration directly, by modify the python package internal files. On my specific machine the file is
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/_sysconfigdata__darwin_darwin.py
The text was updated successfully, but these errors were encountered: