The "remove + install" didn't work. I guess there is still something wrong.
Firstly, I removed the
internal package in the C:\Python37\lib\site-packages\docplex.
Next, I ran the command:
pip install docplex
It showed that 'requirement already satisfied: docplex in ....(2.20.204)'. The reinstallation didn't work. So I figured I should uninstall docplex and reinstall it again. (Maybe a little stupid because I didn't check if docplex works then.) I successfully uninstalled docplex 2.20.204. Then I used 'pip list' to check the installed packages. It was a surprise that I found these in the list (mostly by 'docplex 2.9.133'):
cplex 20.1.0.1
docplex 2.9.133
I tried to solve a model with docplex, and got the following error:
Traceback (most recent call last):
File "D:/Python/Cplex/E-HVRPMBTW V3.py", line 10, in <module>
from docplex.mp.model import Model
ModuleNotFoundError: No module named 'docplex.mp'
I guess 'pip' thinks that 'docplex 2.9.133' is installed in the system but there's nothing to be utilized because I removed the internal package in the C:\Python37\lib\site-packages\docplex.
If I put what's removed back, I got the same error as in the original post:
Traceback (most recent call last):
File "D:/Python/Cplex/E-HVRPMBTW V3.py", line 399, in <module>
mdl.add_constraints(mdl.sum(x[i, j, k] for i in V_without_Vd if i != j for k in K) == 1 for j in L_B)
File "c:\python37\lib\site-packages\docplex\mp\model.py", line 3075, in add_constraints
return self._lfactory._new_constraint_block1(cts)
File "c:\python37\lib\site-packages\docplex\mp\mfactory.py", line 835, in _new_constraint_block1
self._post_constraint_block(posted_cts)
File "c:\python37\lib\site-packages\docplex\mp\mfactory.py", line 840, in _post_constraint_block
ct_indices = self._engine.create_block_linear_constraints(posted_cts)
File "c:\python37\lib\site-packages\docplex\mp\cplex_engine.py", line 747, in create_block_linear_constraints
ranges=range_values)
File "c:\python37\lib\site-packages\docplex\mp\cplex_engine.py", line 133, in fast_add_linear
cpxenv._apienc) as (rmat, nnz):
AttributeError: 'Environment' object has no attribute '_apienc'
I tried to uninstall docplex 2.9.133 but failed. I got the following error:
Found existing installation: docplex 2.9.133
ERROR: Cannot uninstall 'docplex'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
This is where it gets stuck. I can't uninstall the old version of docplex. Hence, I can't install the latest version of docplex.
I will consider your suggestion! Thank you.
------------------------------
Lu Cai
------------------------------
Original Message:
Sent: Tue May 18, 2021 10:26 AM
From: Philippe Couronne
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
From the previous message, it seems clear the ,multiple installations of docplex with different versions of `pip` resulted
in an inconsistent state. After consulting other developers here at IBM the consensus is that only a `rm` operation
on the C:\Python37\lib\site-packages\docplex internal package could remedy this inconsistency.
Once this is done, you can simply reinstall docplex with a "simple" command `pip install docplex`
About the "cplex" module: it is not required if you already have an installation of the COS 20.1. I would recommend to uninstall it,
and add the path to the cplex runtime in your pythonpath environment variable. If COS is installed in <cos_root> and assuming you are on windows,
the runtime is located at <cos_root>/python/3.7/x64_win64: this is the path to add to the PYTHONPATH variable.
Lastly, may I suggest using a "conda" environment, to create one specific Python environment to host docplex/cplex. You can even automate the setting of the PYTHONPATH in the environment.
Anyway, let us know if the "remove + install" works.
We are sorry for the trouble you are facing and plan to improve the distribution of COS/cplex in the future.
Regards.
Philippe.
------------------------------
Philippe Couronne
Original Message:
Sent: Tue May 18, 2021 09:35 AM
From: Lu Cai
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
I ran the command:
pip install --ignore-installed docplex=2.20.204
It showed that I successfully installed the latest version of docplex.
And then I tried to run:
python -m docplex.mp.check_list
However, I got the same error:
Traceback (most recent call last):
File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37\lib\site-packages\docplex\mp\check_list.py", line 148, in <module>
run_docplex_check_list()
File "C:\Python37\lib\site-packages\docplex\mp\check_list.py", line 48, in run_docplex_check_list
from docplex.version import latest_cplex_major, latest_cplex_minor
ImportError: cannot import name 'latest_cplex_major' from 'docplex.version' (C:\Python37\lib\site-packages\docplex\version.py)
This is a screenshot that shows what's in C:\Python37\lib\site-packages\docplex:
The date of the folders highlighted in yellow shows that they were updated last night when I updated docplex from 2.9.133 to 2.20.204 using the following command:
pip install --ignore-installed -U docplex
However, the date of the files highlighted in blue shows that they are the old files that are generated during the installation of docplex 2.9.133 and they are not updated.
And all these files are not updated after successfully reinstalling the latest version of docplex minutes ago.
Here is another screenshot that shows folders related to docplex in C:\Python37\lib\site-packages:
It appears that this command
pip install --ignore-installed docplex=2.20.204
somehow only updated the files in the second folder.
By the way, I did update 'cplex' module after updating docplex yesterday.
All was updated in the following order: docplex - cplex module - COS(installing COS 20.1 after uninstalling COS 12.9). The first two modules were installed in the same way by the following command:
pip install --ignore-installed -U docplex
pip install --ignore-installed -U cplex
And you are right about how I installed the old version of 'cplex' module and docplex.
------------------------------
Lu Cai
Original Message:
Sent: Tue May 18, 2021 07:49 AM
From: Philippe Couronne
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
Thanks for the clarification; this seems to be a conjunction of two problems:
- first the install under COS/python installs both `cplex` and `docplex` (a fixed, old version).
- second, as Docplex is a source package, the way it is handled by `pip` has changed with newer versions, so latest versions of `pip`
have trouble upgrading older versions.
I recommend resetting the installation of docplex to its latest version using
pip install --ignore-installed docplex=2.20.204
Do not install/reinstall the "cplex" module as it would restore again the old docplex module.
Then run the check list script again.
Philippe.
------------------------------
Philippe Couronne
Original Message:
Sent: Tue May 18, 2021 07:04 AM
From: Lu Cai
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
Maybe I was't clear enough. It was in the machine installed with docplex 2.20.204, cplex 20.1.0.1, and CPLEX Optimization Studio 20.1 that I got the above error when trying to solve my model with docplex. I forgot to mention that this machine is also installed with cplex 20.1.0.1(python). And the 'Cplex' mentioned in my original post refers to CPLEX Optimization Studio. I updated cplex(python) from 12.9 to 20.1.0.1 in the same way as I updated docplex.
And yes, on my other machine, docplex 2.20.204 works fine with CPLEX Optimization Studio 12.9. There is no cplex(python) on this machine.
I ran the command:
python -m docplex.mp.check_list
and got this error:
Traceback (most recent call last):
File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37\lib\site-packages\docplex\mp\check_list.py", line 148, in <module>
run_docplex_check_list()
File "C:\Python37\lib\site-packages\docplex\mp\check_list.py", line 48, in run_docplex_check_list
from docplex.version import latest_cplex_major, latest_cplex_minor
ImportError: cannot import name 'latest_cplex_major' from 'docplex.version' (C:\Python37\lib\site-packages\docplex\version.py)
And this is what's in the C:\Python37\lib\site-packages\docplex\version.py:
# --------------------------------------------------------------------------
# Source file provided under Apache License, Version 2.0, January 2004,
#
http://www.apache.org/licenses/
# (c) Copyright IBM Corp. 2015, 2016
# --------------------------------------------------------------------------
# gendoc: ignore
# This file is generated !
# See script tools/gen_version.py
docplex_version_major = 2
docplex_version_minor = 9
docplex_version_micro = 133
docplex_version_string = '2.9.133'
It appears that this file(version.py) is a part of an older version of docplex. The way I updated docplex seems to only update part of the docplex. It does look like an installation issue.
By the way, I ran pip list
to check which version of docplex and cplex are found on my system. This is what I find in the output:
cplex 20.1.0.1
docplex 2.20.204
------------------------------
Lu Cai
Original Message:
Sent: Tue May 18, 2021 04:59 AM
From: Philippe Couronne
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
Hello
docplex2.20 should work fine with cplex 12.9, this looks like an installation issue.
Can you run the following command in an environment where docplex can be found by the PYTHONPATH:
python -m docplex.mp.check_list
and post the output? This checker identifies which version of docplex and cplex are found on your system.
Regards
Philippe.
------------------------------
Philippe Couronne
Original Message:
Sent: Mon May 17, 2021 09:53 AM
From: Lu Cai
Subject: Cplex 20.1 is not compatible with docplex 2.20.204
Hi all,
I have updated my Cplex from 12.9 to 20.1.0(Both under IBM Academic Initiative). Before installing the newest version of Cplex(20.1.0), I have updated my docplex from 2.9.133 to 2.20.204 according to this link:
Decision Optimization
I got the same error as the user in the link when trying to uninstall docplex, so firstly I updated pip from 19.0.3 to 21.1.1 with:
python -m pip install --upgrade pip
Then installed docplex: pip install --ignore-installed -U docplex
After updating both Cplex and docplex, I tried to solve my model. However, I got the following error:Traceback (most recent call last):
File "D:/Python/Cplex/E-HVRPMBTW V3.py", line 399, in <module>
mdl.add_constraints(mdl.sum(x[i, j, k] for i in V_without_Vd if i != j for k in K) == 1 for j in L_B)
File "c:\python37\lib\site-packages\docplex\mp\model.py", line 3075, in add_constraints
return self._lfactory._new_constraint_block1(cts)
File "c:\python37\lib\site-packages\docplex\mp\mfactory.py", line 835, in _new_constraint_block1
self._post_constraint_block(posted_cts)
File "c:\python37\lib\site-packages\docplex\mp\mfactory.py", line 840, in _post_constraint_block
ct_indices = self._engine.create_block_linear_constraints(posted_cts)
File "c:\python37\lib\site-packages\docplex\mp\cplex_engine.py", line 747, in create_block_linear_constraints
ranges=range_values)
File "c:\python37\lib\site-packages\docplex\mp\cplex_engine.py", line 133, in fast_add_linear
cpxenv._apienc) as (rmat, nnz):
AttributeError: 'Environment' object has no attribute '_apienc'
Before I updated anything, docplex 2.9.133 worked fine with Cplex 12.9. Is there anyway to fix this problem?
PS, I have another machine installed with Cplex 12.9 and docplex 2.20.204. It works normally. This is why I believe that the problem behind this is that Cplex 20.1 is not compatible with docplex 2.20.204.
Both of my machines are with win10 and python 3.7.3.
Thanks in advance.
------------------------------
Lu Cai
------------------------------
#DecisionOptimization