3

I have purchased a cplex subscription and received a key to use, but I can't figure out how to use it, no matter what I try I keep getting the "no key, go purchase cplex here" error.

I'm using cplex via docplex in a jupyter notebook running in Ubuntu 20.04. All the python stuff is installed using anaconda, cplex and docplex have been installed using the conda install command listed here: https://developer.ibm.com/docloud/blog/2017/01/23/cplex-python-now-available-anaconda-cloud/

This seems to work fine and I can solve small problems, but for larger problems it throws an error telling me to buy the full product. I have, and I have set the CPLEX_STUDIO_KEY environment variable, but the error remains. I can't find any documentation beyond "set this env. var." and the error just assumes you haven't purchased it instead of being of any help..

What am I missing?

Threore
  • 33
  • 4

1 Answers1

3

The official documentation for entering your CPLEX API key can be found here (you've probably already seen this). This documentation assumes that you have installed the Community Edition (aka, the "free edition") of CPLEX Optimization Studio and you can find a link to download that here. You can do that, if you like, and you should be up and running.

An alternative is to use the undocumented CPLEX_CPXCHECKLIC_BINDIR environment variable. This is particularly useful for Python users that may not choose to install the rest of CPLEX Optimization Studio. When you installed the cplex package into your anaconda environment (or for others that installed via pip), it included an executable named cpxchecklic. This can be found in the bin or Scripts directory of your Python environment. If you set the CPLEX_CPXCHECKLIC_BINDIR environment variable to the directory that contains cpxchecklic, and you have already set the CPLEX_STUDIO_KEY environment variable correctly, then you should be good to go.

If you continue to have problems after following the advice above, the following Python script may come in handy to help with troubleshooting problems you're having with your API key (please update your question with the output if that is the case):

"""Tests Python Download-and-go setup.

usage: python test.py [API_KEY] [CPXCHECKLIC_BINDIR]

The API_KEY and CPXCHECKLIC_BINDIR arguments are optional.
"""
import os
import sys

import cplex

# Column limit for the Community Edition.
CPLEX_COLUMN_LIMIT = 1000

# Print the CPLEX version.
print("Version:", cplex.__version__)

# Allow the user to pass in the API key.
if len(sys.argv) > 1:
    os.environ["CPLEX_STUDIO_KEY"] = sys.argv[1]

# Allow the user to pass in the cpxchecklic bindir.
if len(sys.argv) > 2:
    os.environ["CPLEX_CPXCHECKLIC_BINDIR"] = sys.argv[2]

# Print the environment variables.
for var in ("CPLEX_STUDIO_KEY",
            "CPLEX_STUDIO_DIR1210",
            "CPLEX_CPXCHECKLIC_BINDIR"):
    print(var, "=", os.getenv(var))

# Create a model that will not work with the Community Edition.
cpx = cplex.Cplex()
cpx.variables.add(lb=[0.0] * (CPLEX_COLUMN_LIMIT + 1))

# Solve the model and print the solution status.
cpx.solve()
print("Status: {0} ({1})".format(cpx.solution.get_status_string(),
                                 cpx.solution.get_status()))
rkersh
  • 4,447
  • 2
  • 22
  • 31
  • 2
    Setting the CPLEX_CPXCHECKLIC_BINDIR env var did the trick, thank you so much! Was there somewhere I should have found out about that? – Threore May 06 '20 at 15:19