6

I'm trying to rerun an older code (about a year old). I have installed academic version of CPLEX 22.1.1 version and Python API and docplex in python. However, the dependencies have changed and therefore I am unable to run the code now.

Traceback (most recent call last):
  File "C:\Users\...\Desktop\Jakhu\iitk\Sem3\Codes\Possibly_smart\Master.py", line 4, in <module>
    from docplex.mp.model import Model
  File "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\docplex\mp\model.py", line 16, in <module>
    from docplex.mp.aggregator import ModelAggregator
  File "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\docplex\mp\aggregator.py", line 14, in <module>
    from docplex.mp.utils import is_number, is_iterable, is_iterator, is_pandas_series, \
  File "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\docplex\mp\utils.py", line 70, in <module>
    __float_types.add(numpy.float_)
                      ^^^^^^^^^^^^
  File "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\numpy\__init__.py", line 411, in __getattr__
    raise AttributeError(
AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.. Did you mean: 'float16'?

I tried installing numpy version using pip install --force-reinstall numpy==1.19.5 and pip install docplex==2.10.154 to make it compatible but it still throws the same error.

I cannot change the aliases of numpy.float since they are arriving from docplex and are outside my control.

What is happening here? How do I resolve this? Many thanks for reading!

5
  • Have you tried to update your docplex version? pypi lists an Apr 2024 release which should work with the current numpy. 2.27.239. 2.10 dates back to 2019!
    – hpaulj
    Commented Apr 18 at 17:23
  • I started with the latest versions of the packages and they showed the same error. I depreciated the versions in the hope that aliases would work and not throw this error. I'll update them : )
    – Meet Saiya
    Commented Apr 19 at 3:51
  • Updated numpy==2.0.0b1 and docplex==2.27.239 and the issue persists. CPLEX is 22.1.1.0 academic license.
    – Meet Saiya
    Commented Apr 19 at 4:59
  • This is only a hack, and may not work, but have you tried simply setting np.float_ = np.float64 in your script after importing numpy? You can overwrite or create new attributes of an imported package, although it is generally not recommended.
    – Daniel F
    Commented Apr 19 at 12:12
  • In IBM community see community.ibm.com/community/user/ai-datascience/discussion/… Commented Jul 9 at 14:44

3 Answers 3

7

Do:

pip install "numpy<2"

Or

import numpy as np
np.float_ = np.float64
1
  • 1
    I was getting similar errors from fb Prophet library, and adding np.float_ = np.float64 fixed the related issues for me without having to downgrade the numpy package; thanks.
    – ezadeh
    Commented Aug 28 at 11:31
3

Please try to downgrade numpy (for example, version 1.26.4) while keeping docplex==2.27.239

2
  • Did that, upgraded back. It works with latest numpy too. It just needs older python.
    – Meet Saiya
    Commented Apr 19 at 13:42
  • @MeetSaiya which python ver should we use?
    – SimZhou
    Commented Jun 26 at 2:47
0

It seems that docplex does not support python 3.11 or higher. It's only supported up to 3.10. I installed Python 3.10 and changed the PyCharm interpreter to 3.10 I also manually opened utils.py from "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\docplex\mp\utils.py" path and updated __float_types.add(numpy.float_) to __float_types.add(numpy.float64) to get rid of numpy error.

The program executes without any errors as of now. I'll cross check with a known previous solution to check for errors.

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.