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 228 forks source link

Python does not recognize my academic version #64

Closed JefVL closed 2 years ago

JefVL commented 2 years ago

I installed cplex on my computer and tried to install the python API using python setup.py install --home \User\AppData\Local\Programs\Python\Python310\Lib\site-packages.

However when i use the code from docplex.mp.model import Model and try to solve a model, I get the error message:

DOcplexLimitsExceeded: **** Promotional version. Problem size limits (1000 vars, 1000 consts) exceeded, model has 1938 vars, 508 consts, CPLEX code=1016

I don't know how I can ge the academic version instead of the promotional one.

vlkong commented 2 years ago

There are multiple issues: 1 - What is the name of the installer you use ? This can help determine if you installed the academic version or the CE version 2 - I recommand that you don't use the --home option unless you know exactly what you are doing (the directory you want to pass is proabbly not Python310\Lib\site-package) - Just use python setup.py install or better pip install .

Can you please make sure that the installer does not have preview in it ? If you downloaded it from academic initiative, then it should be good, otherwise please make sure you download it from Academic Initiative.

JefVL commented 2 years ago

Thank you for the information, the installer's name is CPLEX_Studio_Community201. I think this is indeed the wrong version. I'll attemnpt to download the Academic Initiative one.

JefVL commented 2 years ago

I have installed the non-community version and ran the command python setup.py install. Yet when I attempt to implement the code from docplex.mp.model import Model, python still only lets me use the 'promotional version'.

vlkong commented 2 years ago

Did you make sure you pip uninstall cplex before your python setup.py install ? Most probably, you had a CE version installed before.

If you did pip uninstall cplex, we need to check that you are using the same python environment in the command line and in your code.

Please check it using: 1 - In the terminal window where you ran python setup.py install, please run command:

where python

Then

python --version

2 - in your code:

import sys
print(sys.version)

import docplex
print(docplex.__path__)

Please let me know the result of both commands. I'm expecting print(sys.version) to yield the same result than python--version and where python to point to the python executable corresponding to the lib where docplex.__path__ is.

JefVL commented 2 years ago

cplex was uninstalled. For the commands where python resulted in the following output: C:\Users\Marie\AppData\Local\Programs\Python\Python310\python.exe C:\Users\Marie\AppData\Local\Microsoft\WindowsApps\python.exe

python--version returned 3.10.2 print(sys.version) returned 3.9.7 print(docplex.__path__) returned ['C:\Users\Marie\anaconda3\lib\site-packages\docplex']

As these shouldn't be different I guess that is where the problem lies, I don't know how to change this though.

vlkong commented 2 years ago

What development tool (IDE) are you using ? Mainstream IDEs like PyCharm or VSCode have good documention on how to setup / change the python environment they use. For instance, for VSCode: https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

vlkong commented 2 years ago

Just also realized that you have a selection of python3.9 and python3.10 - What version of CPLEX Optimization Studio are you using? You might need to install python 3.8 (as we don't support python3.9 and 3.10 yet)

JefVL commented 2 years ago

I am currently using Jupyter notebook but I am also familiar with Pycharm. Can I work with Jupyter for cplex or is that not possible? I will download python 3.8.

vlkong commented 2 years ago

You can of course work with jupyter.

I see in the logs above that you have anaconda3 on your machine. The best thing is to create a conda python 3.8 virtual environment using conda, activate that environment then install the CPLEX wrappers. Then you can install jupyter and develop with CPLEX and jupyter.

For more info about conda virtual environments: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

JefVL commented 2 years ago

Setting up a virtual environment with python version 3.8 fixed the issue. Thanks for all the information!