Decision Optimization

 View Only
Expand all | Collapse all

Using academic edition of CPLEX from python

  • 1.  Using academic edition of CPLEX from python

    Posted Fri June 03, 2022 02:03 PM
    Hi,

    I am trying to use the academic edition of CPLEX on my mac and I want to use python to call CPLEX. I have downloaded and installed CPLEX academic edition studio. After running this command  "python /Applications/CPLEX_Studio221/python/setup.py install" I get this error:

    error: could not create '/Library/Python/3.8': Permission denied

    Then I run the command with sudo and then I get these errors like the below one:


        def print(cls, out, model):

                ^

    SyntaxError: invalid syntax

    I then tried this command:

    sudo python3 /Applications/CPLEX_Studio221/python/setup.py install

    This time it seems that it is installing the CPLEX. But still, there is another error. 

    When I enter these commands in my terminal to see if I can import cplex, 

    python 
    import cplex

    I get this error:

    ModuleNotFoundError: No module named 'cplex'
    But if I enter these commands in the terminal:

    python3
    import cplex

    I would get this error:

    Traceback (most recent call last):

      File "<stdin>", line 1, in <module>

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/__init__.py", line 44, in <module>

        from .aborter import Aborter

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/aborter.py", line 13, in <module>

        from ._internal import _procedural as _proc

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/__init__.py", line 20, in <module>

        from . import _list_array_utils

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/_list_array_utils.py", line 14, in <module>

        from . import _pycplex as CPX

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/_pycplex.py", line 13, in <module>

        from . import _pycplex_platform

      File "/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/_pycplex_platform.py", line 26, in <module>

        from cplex._internal.py39_cplex2210 import *

    ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/py39_cplex2210.so, 2): no suitable image found.  Did find:

    /opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/py39_cplex2210.so: mach-o, but wrong architecture

    /opt/homebrew/lib/python3.9/site-packages/cplex-22.1.0.0-py3.9.egg/cplex/_internal/py39_cplex2210.so: mach-o, but wrong architecture


    Any ideas? I just want to say that when I enter the python command in my terminal I get python 3 by default.




    ------------------------------
    Shahrooz Pouryousef
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Using academic edition of CPLEX from python

    Community Leadership
    Posted Tue June 07, 2022 04:18 AM
    Hi Shahrooz,

    Seeing that the first error refers to Python 3.8, but the other refers to 3.9, I very much suspect that you have multiple versions of Python installed, and that `python` and `python3` don't refer to the same versions.  You can check with `python --version` and `python3 --version`.  If both versions are supported for CPLEX Optimization Studio, you can choose whichever you want.  But the one you use to run the installation script should be the same as the one you subsequently use to run CPLEX.

    You can of course install CPLEX in both versions. To do this, you have to run the install script once with each version of Python.

    If you don't use virtual environments already, I suggest you learn about them at https://realpython.com/python-virtual-environments-a-primer/.

    ------------------------------
    Xavier
    ------------------------------