I am installing Cplex python API into my MacBook. So I followed the tutorial given in YouTube (https://www.youtube.com/watch?v=oINxanpv_2M) and have installed the script & library for Cplex using the Terminal instructions:
cd /Users/my_name/IBM_CPLEX/CPLEX_Studio1210/python
python3 setup.py install
this part works alright with everything installed, just a note from the Terminal at the beginning saying 'python wrapper is not found'.
Then I tested an existing Cplex problem using
cd IBM_CPLEX/CPLEX_Studio1210/python/examples/mp/modeling
python3 production.py
, which returned:
Model: production
- number of variables: 6
- binary=0, integer=0, continuous=6
- number of constraints: 5
- linear=5
- parameters: defaults
Traceback (most recent call last):
File "production.py", line 101, in <module>
if model.solve():
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/docplex/mp/model.py", line 4152, in solve
return self.fatal("CPLEX runtime not found: please install CPLEX or solve this model on DOcplexcloud")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/docplex/mp/model.py", line 884, in fatal
self._error_handler.fatal(msg, args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/docplex/mp/error_handler.py", line 210, in fatal
raise DOcplexException(resolved_message)
docplex.mp.utils.DOcplexException: CPLEX runtime not found: please install CPLEX or solve this model on DOcplexcloud
So my initial guess is that my python 3 has been installed in another directory under the Library folder, and a path will be needed to link the Cplex engine to the python solver (if correct). Inside the YouTube tutorial, a PATH is actually provided, so in my case it's written as:
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
export PYTHONPATH=/Users/my_name/IBM_CPLEX/CPLEX_Studio1210/cplex/python/3.7/x86-64_osx
I have actually installed Cplex python API into a Windows PC previously. The path-adding step was done by visiting: Control Panel -> System and Security -> System -> Advanced system settings -> Environment Variables. Visit (https://www.youtube.com/watch?v=hqGZzRh00y0) for specific further steps.
However, I tried quite a lot of ways adding this path to my Mac, and so far I've used those to write the above path but none worked:
nano .bash_profile.pysave
nano .bash_profile
sudo nano /etc/paths
That's where I got stuck. Any help and comment would be highly appreciated. I am new to Mac Terminal. Anaconda is also installed in my Mac if that's helpful.
Sorry for the massive details - was trying to put down everything in case there was something unnoticed that I have done wrong. Thanks.
Added:
A small issue in the process above was that my Python was actually 3.8. So after adding the path export PYTHONPATH=/Users/my_name/IBM_CPLEX/CPLEX_Studio1210/cplex/python/3.7/x86-64_osx
and running a cplex example, a message popped up inside the Terminal:
Exception: CPLEX 12.10.0.0 is not compatible with this version of Python.
Need to download an older 3.7 version then did the $ python3.7 setup.py install
process again after changing my directory to IBM_CPLEX/CPLEX_Studio1210/python
.
Some similar issues about Python version have been discussed in the post: CPLEX and Python 3.7.