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

Cannot import pySLSQP on mac-m1 #38

Closed
haotang1995 opened this issue Jan 14, 2022 · 5 comments
Closed

Cannot import pySLSQP on mac-m1 #38

haotang1995 opened this issue Jan 14, 2022 · 5 comments

Comments

@haotang1995
Copy link

Hi, I have a similar issue to this. I managed to install pyOpt on my system (mac-m1, 12.1, py3.8.8, gfortran) without errors and have done everything as suggested. However, I cannot import SLSQP as well.

I am now stuck with the error while "import slsqp" in the pyOpt/pySLSQP directory. The error message said that "mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')"
May I ask if this is expected? And is there a solution to use pyOpt on mac-m1? Thanks!

@madebr
Copy link
Owner

madebr commented Jan 15, 2022

You need to pass -arch arm64 to the compiler/linker.
I think you can do this by using CFLAGS.

CFLAGS="-arch arm64" setup.py build_ext

Perhaps you need to define LDFLAGS as well.

LDFLAGS="-arch arm64" CFLAGS="-arch arm64" setup.py build_ext

If you need other extra compiler arguments, such as -isysroot, I can't really help you further as I don't own anything Apple.

@haotang1995
Copy link
Author

Hi madebr, thanks for the hint and the quick reply! The "CFLAGS & LDFLAGS" didn't work, but I do find a related suspicious point:
In my environment, the default --plat-name in "python setup.py build" is macosx-10.9-x86_64, which may well explain the reason for compiling pySLSQP in x86_64.

However, I couldn't find the valid plat-name for mac 12.1 arm64 on Internet... Do you have any further suggestions? I will surely search more. Thanks!

@madebr
Copy link
Owner

madebr commented Jan 15, 2022

First of all, make sure you're running a python arm executable.
After some googling, I found a user having success by doing export ARCHFLAGS="-arch arm64".

@haotang1995
Copy link
Author

Thanks~ I will try it later. I am now reinstalling pure python without conda to make the environment simple and standard, after some googling as well. I will definitely try the suggestion after that. Thanks!

@haotang1995
Copy link
Author

Hi @madebr , thanks again for the help! The problem is from conda... After re-installing python3.9 without conda, the default value of plat-name for "python setup.py build_ext" becomes "macosx-10.9-universal2". The installation went smoothly afterward.
(Just for others' convenience, numpy-ext has strict version control and, for now, it only supports numpy-1.21 which is not supported in my environment. This incompatibility resulted in failures while installing numpy-ext using pip. I just removed this constrain in requirement.txt in numpy-ext and installed it manually using "setup.py". All tests of numpy-ext were passed and pyOpt ran smoothly.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants