No matching distribution found for cplex
Asked Answered
B

2

6

When installing the Python CPLEX API with pip install cplex, I get the error:

Could not find a version that satisfies the requirement cplex (from versions: none) 
ERROR: No matching distribution found for cplex

My python and pip installation are up-to-date. I just have installed the CPLEX optimizer. Where should I start to determine the problem?

Bryophyte answered 17/6, 2020 at 19:37 Comment(2)
first visit page with cplex to see if there are some information. Maybe there is no version for your Python ie. 2.7 (too old) or 3.8 (too new) and you have to use different Python version. If code is on GitHub then there should be page Issues and there you can see if someone had similar problem.Heigho
on page pypi.org/project/cplex/#files you can see there is vesion only for Python 3.6 and 3.7 - if you use different version the you have to install Python 3.7Heigho
A
3

The CPLEX python API (python package cplex) is only available on PyPI for python 3.6 and 3.7 (as furas pointed out in the comments). However, you can download source code from PyPI, and run it other versions of python. It runs fine in python 3.8 (as far as I can tell).

To do this:

  1. Download the Wheel file for your system from https://pypi.org/project/cplex/#files
  2. Unzip the Wheel file.
  3. Copy the cplex directory from cplex-12.10.0.3.data/purelib/ to somewhere on your python path.
  4. Test with python -c "import cplex; print(cplex.__version__)". This should print the CPLEX version, e.g. 12.10.0.0.
Andie answered 3/12, 2020 at 0:5 Comment(0)
T
0

I tried Matt's brilliant workaround (Thanks mate!) on a conda 3.8 environment in January 2021, and it almost worked. I just had to edit a file inside cplex to avoid the following exception, and make it work:

Exception: CPLEX 12.10.0.0 is not compatible with this version of Python.

So, to keep it comprehensive, here are Matt's steps, together with the extra edit I had to add:

  1. Download and unzip the wheel (in my case the closest was Linux, x86, py37) from here: https://pypi.org/project/cplex/#files
  2. Unzip it and make sure that the purelib/cplex directory is in your Python path (e.g. by opening the python interpreter inside the purelib directory.
  3. now import cplex triggered the error above. This can be circumvented by editing the version_info < (3, 8, 0) expression in cplex/internal/_pycplex_platform.py, and replacing it with e.g. version_info < (3, 9, 0).

Now import cplex will work!

PLEASE NOTE that this doesn't mean the installation is guaranteed to be successful. There is a reason why the IBM devs put that version guard in place. The library hasn't (likely) been tested on Python 3.8 and this workaround may be unstable! For prototyping purposes though it may be enough. Please let me know if you have any issues, and again thanks Matt for doing all the brainwork.

Cheers!
Andres

Tidbit answered 6/1, 2021 at 13:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.