python_noob
python_noob

Reputation: 129

Is there any way to get cffi to install both x86_64 and arm64 mach-o files on a Macbook(M1)?

I am really pulling my hair out onf this one. I upgraded python from 3.9 to 3.11 on my Macbook (M1 Max chip) yesterday and reinstalled all the packages via pip. Everything seemed to work well, until I wanted to run my program that uses the module netmiko.

In the mac terminal and in iterm2, everything worked as expected. However, if I try to use the terminal in VSCode, I get the following error message:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I don't understand why VSCode needs to use an x86_64 mach-o file when it is on a Mac.

I tried to fix the problem by reinstalling cffi, argon2-cffi and netmiko.
The funny thing is that if I reinstall cffi from within VSCode, cffi will create the necessary x86_64 mach-o but will not install the arm64 version needed for the mac terminal as seen here:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

So the problem lies either with pip or cffi, since they refuse to create both versions. Is there a way to get cffi to create both mach-o versions on my Macbook?

Thanks

Upvotes: 2

Views: 1243

Answers (1)

akarca
akarca

Reputation: 1516

First uninstall cffi:

pip uninstall cffi

Then install cffi from source for arm64

arch -arm64 pip install --no-cache cffi --no-binary :all:

Upvotes: 1

Related Questions