IBMDecisionOptimization / docplex-examples

These samples demonstrate how to use the DOcplex library to model and solve optimization problems.
https://ibmdecisionoptimization.github.io/
Apache License 2.0
396 stars 229 forks source link

Cplex runtime not found #19

Closed GigPython closed 5 years ago

GigPython commented 5 years ago

I installed anaconda, cplex 12.9 on my mac. I also installed Docplex using the command pip install docplex and set the variable environment : PYTHONPATH as it is explained in IBM website. However each time I try to run a code in python I got this error : Cplex runtime not found. Please install Cplex. I can’t figure out where is the problem. Any help would be very appreciated. Thank you

vlkong commented 5 years ago

Hi,

If you installed cplex studio, can you please make sure that $CPLEX_STUDIO_DIR129/cplex/python/3.6/x64_win64 (replace 3.6 by your actual python version) directory is in your PYTHONPATH ?

If you did not install cplex studio but just the cplex lib from anaconda or pypi, I will need you to dump your PYTHONPATH and PATH to check your environment.

Thanks

vlkong commented 5 years ago

Let's check that cplex is working.

Can you please run this in a shell ?

python -c "import cplex; print(cplex.__version__)"

(it should print 12.9.0.0)

If this works, then we will need to check that the python env you are using with your docplex model knows about the PYTHONPATH you set there. In your python script where you have your "cplex not found error", right before you create a model, can you print the contents of sys.path ?

vlkong commented 5 years ago

sys.path does not contain your /Applications/CPLEX_Studio129/cplex/python/3.7/x86_64-osx directory, as you set in your .bash_profile.

You set the PYTHONPATH in your .bash_profile, so you need to run your python in a subprocess of a bash.

I'm not an OSX user, but as far as I remember, you must use launchctl to set system environment variables (something like launchctl setenv PYTHONPATH /Application/CPLEX_Studio129 etc...)

Can you please set PYTHONPATH as a system environment variable and try again ?

Thanks

vlkong commented 5 years ago

If you don't know how to set environment variables, I would advise you to just install the CPLEX python libraries in your python environment. This is described in the 'Setting up CPLEX' (aka installation guide) of CPLEX: https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.cplex.help/CPLEX/GettingStarted/topics/set_up/Python_setup.html

Just make sure you are running the python interpreter that goes with your /Users/infotech/anaconda3

Thanks

GigPython commented 5 years ago

Setting up Python API using either the script setup.py or the environment variable Pythonparh is exactly what I've done ( and as far as I know, to be able to do so cplex studio must be installed. Am I wrong ?) The result I get whenever I run code in python was : cplex runtime not found. It has to noted that I used this method in a windows PC and it worked perfectly. In my mac I couldn't figure why it doesn't work and how to fix the problem. As for your last remark. I didn't get it. How to make sure that the interpreter goes with the directory. And should I need to uninstall cplex studio ? Thanks

vlkong commented 5 years ago

Hello,

No, you didn't run the setup script. If you did, then cplex would have been installed in your sys.path. This is different from setting up a PYTHONPATH.

On mac, 100% of the errors of this type I have seen are due to users running python in a terminal, and using another python in their IDE. This is because Mac comes with its own installation fof python, which your IDE could have picked up (I can't check, you deleted your post with the screenshots of your sys.path). On windows this is easier: There is no system python so when you install python, there's only one. On Mac, I often see at least 2 installations.

You can check the python executable you use in your script where you have your error by checking the value of sys.executable (This is probably a good test: print(sys.executable) from a python you run in a Terminal window, then same thing in your script and we'll be sure you are using the right python).

Please also do not delete comments in this issue, it makes it difficult to follow what happened and makes it difficult for me to check what we already tryied (in this instance, I cannot check the paths you previously copy here).

Edit: you don't need to install your cplex stdio. Just run CPLEX_Studio129\cplex\python\3.7\x86_64-osx\setup.py with the same python interpreter than the one used by your IDE.

Thanks

GigPython commented 5 years ago

Hello,

No, you didn't run the setup script. If you did, then cplex would have been installed in your sys.path. This is different from setting up a PYTHONPATH.

On mac, 100% of the errors of this type I have seen are due to users running python in a terminal, and using another python in their IDE. This is because Mac comes with its own installation fof python, which your IDE could have picked up (I can't check, you deleted your post with the screenshots of your sys.path). On windows this is easier: There is no system python so when you install python, there's only one. On Mac, I often see at least 2 installations.

You can check the python executable you use in your script where you have your error by checking the value of sys.executable (This is probably a good test: print(sys.executable) from a python you run in a Terminal window, then same thing in your script and we'll be sure you are using the right python).

Please also do not delete comments in this issue, it makes it difficult to follow what happened and makes it difficult for me to check what we already tryied (in this instance, I cannot check the paths you previously copy here).

Edit: you don't need to install your cplex stdio. Just run CPLEX_Studio129\cplex\python\3.7\x86_64-osx\setup.py with the same python interpreter than the one used by your IDE.

Thanks

GigPython commented 5 years ago

Problem solved !! Thank you so much