Decision Optimization

 View Only
  • 1.  Cplex Python package not working on ARM64 architecture

    Posted Wed January 04, 2023 01:29 PM
    Edited by System Fri January 20, 2023 04:46 PM
    I installed CPlex version 22.1.1 - ARM64 for OSX and can run problems through the CPlex studio properly.

    However, I can't get to make the python API work.

    I am running a Macbook Pro with M1 chip (ARM64 achitecture).

    The code I try to run:
    Python 3.10.9 (v3.10.9:1dd9be6584, Dec  6 2022, 14:37:36) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cplex​


    The error I get

    ImportError: dlopen(/Applications/CPLEX_Studio2211/cplex/python/3.10/arm64_osx/cplex/_internal/py310_cplex2211.so, 0x0002): tried: '/Applications/CPLEX_Studio2211/cplex/python/3.10/arm64_osx/cplex/_internal/py310_cplex2211.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/CPLEX_Studio2211/cplex/python/3.10/arm64_osx/cplex/_internal/py310_cplex2211.so' (no such file), '/Applications/CPLEX_Studio2211/cplex/python/3.10/arm64_osx/cplex/_internal/py310_cplex2211.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

    The error suggests that python or the cplex python package requires x86_64 architecture, but only arm64 is available (which makes sense, since I installed the arm64 version of CPlex 22.1.1). 

    My PYTHONPATH points to the correct CPlex installation and I installed the python package using the setup.py script as per the instructions found in the documentation here.

    Is there a way to run the setup.py script in a way that is compatible with ARM64 arch? Or any other workaround to make the python API work?

    Thanks!

    ------------------------------
    Pierre Antoine Vaillancourt
    ------------------------------
    #DecisionOptimization


  • 2.  RE: Cplex Python package not working on ARM64 architecture

    Posted Wed January 04, 2023 01:45 PM
    To me this most likely indicate that your python interpreter is running as intel mode, not as M1 arm64.
    When downloading a python installer, you generally have the choice between intel only and universal2 installer, are you sure you installed the 2nd?
    If so, try running the python as `arch -arm64 python ....` to force the arm64 mode.

    ------------------------------
    Vincent Beraudier
    ------------------------------



  • 3.  RE: Cplex Python package not working on ARM64 architecture

    Posted Mon January 09, 2023 12:30 PM
    Pierre-Antoine, did the arch command solve your compatibility problem?

    Vincent: How can we know if our python interpreter is in intel mode or arm64 mode?

    ------------------------------
    Laurent Houssin
    ------------------------------



  • 4.  RE: Cplex Python package not working on ARM64 architecture

    Posted Tue January 10, 2023 03:35 AM
    AFAIK a universal2 python interpreter will run intel mode by default. So you have to manually switch the mode.

    If you are interested in arm only python, you may have a look at the anaconda or miniconda arm64 installers. Or you can create anaconda envs which are specific for an architecture, see https://stackoverflow.com/questions/65415996/how-to-specify-the-architecture-or-platform-for-a-new-conda-environment-apple for example.

    Beware that on Mac Mx, it is very easy to mess up a python environment by installing mixed platform libraries.

    ------------------------------
    Vincent Beraudier
    ------------------------------



  • 5.  RE: Cplex Python package not working on ARM64 architecture

    Posted Tue January 10, 2023 10:26 AM
    Running `arch` by itself in the terminal will tell you if you are running the terminal in arm64 or in intel (i386). Python will run according to your terminal's architecture (if you installed the universal python installer for mac osx).
    You can run `arch -arm64 python ....` to ensure that your python interpreter is running in arm64 mode. 


    ------------------------------
    Pierre Antoine Vaillancourt
    ------------------------------



  • 6.  RE: Cplex Python package not working on ARM64 architecture

    Posted Tue January 10, 2023 10:22 AM
    Indeed, the `arch` command in my terminal revealed that my terminal was in intel mode and so was my python interpreter. Running python as you suggested (`arch -arm64 python ....`) fixed the issue.
    As for why my terminal was not running in arm64, it was a configuration issue with VSCode.

    Thanks for your help!


    ------------------------------
    Pierre Antoine Vaillancourt
    ------------------------------



  • 7.  RE: Cplex Python package not working on ARM64 architecture

    Posted Fri January 13, 2023 08:47 AM
    Thank you for your help. My python was already running in arm64 mode. The problem was a conflict between the previous version I installed of Cplex (cplex_studio2211-osx that was no good for my Mac M1) and the new and good version of cplex (cplex_studio2211-osx-arm64 that is the Mac M1 version of cplex). Thank you all.

    ------------------------------
    Laurent Houssin
    ------------------------------