Setting up a Python environment

To get started using the Mathematical Programming Modeling for Python feature of IBM® Decision Optimization CPLEX® Modeling for Python, you first need to verify that your system meets the requirements and install Python and DOcplex. As an alternative, you can choose to use the Data Scientist Workbench and not need to install anything on your computer.

System requirements

  • Python with version >= to 2.7.9, 3.4.x, or 3.5.x on 64-bit operating systems: Available from Python.org.
    • Python version lifespans: here
    • The Python version you choose must matcht the CPLEX one if you solve locally.
  • Only Windows, Mac and Linux operating systems are supported. Your computer must support SSL.
  • See the section on Troubleshooting for help diagnosing installation and execution problems.

Get Python development tools

  • If you are new to Python, you might want a development studio with editors and debuggers. Both PyCharm and PyDev have free editions.
  • You can download Python 2.7.9, 3.4.2, or 3.5.2 from Python.org.
  • A good alternative is to use Anaconda, which includes a Python interpreter and over 195 of the most popular Python packages for science, math, engineering, and data analysis.
  • You can also turn a Visual Studio into a Python editor. See Python Tools for Visual Studio project from Microsoft.

Installing the CPLEX modeling library with pip

The IBM Decision Optimization CPLEX Modeling for Python (DOcplex) library can be installed via pip from PyPI.

Use pip to install the modeling library:

> pip install docplex

pip is the standard tool that is used to install Python packages and is included in Python 2.7.9 (and later), Python 3.4 (and later), and Python 3.5 (and later). See pip for more details. Refer to the pip documentation for easy access to the upgrade, uninstall, and version checking commands.

See README.md for a detailed list of dependencies that are automatically downloaded and installed.

Installing the CPLEX modeling library with conda install packager

The IBM Decision Optimization CPLEX Modeling for Python (DOcplex) library can be installed via conda from the CPLEX conda home.

First install Anaconda, then use conda to install the modeling library:

> conda install -c ibmdecisionoptimization docplex

conda is the package installer that is used to install Python packages and is included in Continuum Anaconda distributions. Refer to the anaconda documentation for easy access to the upgrade, uninstall, and version checking commands.

See README.md for a detailed list of dependencies that are automatically downloaded and installed.

Try out DOcplex, no local installation required!

The easiest way to start experimenting with DOcplex does not involve installing anything on your computer.

Here are 2 free services to run Python code:

  • IBM Data Science Experience is an IBM service that provides a hosted notebook service in the cloud. It provides both Jupyter and Zeppelin notebooks.

Create an account and have access to Python from within your browser via a Jupyter Notebook in a few minutes. Then simply run pip install docplex to start writing optimization models and register to DOcplexcloud.

You can get more details about what notebooks are here and here

Managing environments

You might want to have a look at Virtual Environment and Conda Environment to help you manage your Python installation base and keep your global site-packages directory clean and manageable.

Troubleshooting