2

I would like to use scikit-optimize's BayesSearchCV and using the following package versions in my environment myEnv:

# Name                    Version                   Build                 Channel
python                    3.10.8                    h4a9ceb5_0_cpython    conda-forge
numpy                     1.24.1                    pypi_0                pypi
scikit-optimize           0.8.1                     pyh9f0ad1d_0          conda-forge

and I am getting the error

AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'?

FYI: The full error message is as follows

Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/sklearnex/__main__.py", line 55, in <module>
    sys.exit(_main())
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/sklearnex/__main__.py", line 52, in _main
    runf(args.name, run_name='__main__')
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "bayes_helper.py", line 26, in <module>
    from skopt import BayesSearchCV
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/__init__.py", line 44, in <module>
    from . import callbacks
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/callbacks.py", line 17, in <module>
    from skopt.utils import dump
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/utils.py", line 19, in <module>
    from .sampler import Sobol, Lhs, Hammersly, Halton, Grid
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/sampler/__init__.py", line 4, in <module>
    from .lhs import Lhs
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/sampler/lhs.py", line 9, in <module>
    from ..space import Space, Categorical
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/__init__.py", line 5, in <module>
    from .space import *
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/space.py", line 212, in <module>
    class Real(Dimension):
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/skopt/space/space.py", line 253, in Real
    name=None, dtype=np.float):
  File "/home/ec2-user/anaconda3/envs/myEnv/lib/python3.10/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'?

It seems that there is some compatibility issue between my numpy version and my scikit-optimize version. But I don't find what it is. In the scikit-optimize documentation it just says that NumPy (>= 1.13.3) is required. Which is the case for me. I also tried it with the very latest version of scikit-optimize which is 0.0.9, but I still get this error.

Can anyone help me with solving this issue? I can provide any other package version information if needed.

PeeteKeesel
  • 634
  • 1
  • 7
  • 18
  • 1
    This was definitely fixed with 0.9.0 via [this PR](https://github.com/scikit-optimize/scikit-optimize/pull/1023). So, verify that you are correctly installing 0.9.0. Everything works fine for me with `numpy=1.24.1` and `scikit-optimize=0.9.0`, either with `python=3.10` or `python=3.11`. – merv Jan 17 '23 at 16:47
  • I am also getting this error with python3.11 and optimize @ v 0.9.0. Unfortunately, `numpy v 1.19` is no longer distributed as a binary on WSL, and python3 is not available below `3.10` on WSL. So to get this library working, you must manually compile some earlier version of python. @merv – Chris Feb 26 '23 at 20:45
  • @merv I made the [following PR](https://github.com/scikit-optimize/scikit-optimize/pull/1152) to address it; this library is virtually impossible to use on WSL (Windows Subsystem for Linux) with pip/venv managed environments without the fix. – Chris Feb 26 '23 at 20:57

1 Answers1

1

NumPy abolished types like np.int and np.float, they are deprecated since 1.20, instead standard builtin types int, float or special types like np.int32 should be used.

In short your scikit-optimize and NumPy versions are not compatible. First you could try to update the package to the newest version of 0.9.
As well can edit that line of code manually in your installation (replace it with float) and test if it works (chance is high).

Else downgrade your numpy to below 1.20. Below 1.24 it still works but will give you a warning

Daraan
  • 1,797
  • 13
  • 24
  • Thanks for the response. If I update to the newest version `0.9.0` I get a similar error `AttributeError: module 'numpy' has no attribute 'int'. Did you mean: 'inf'?`. And if I downgrade numpy then I can't use python `3.10` anymore, which is unfortunately my requirement. – PeeteKeesel Jan 17 '23 at 16:37
  • Then the only suggestion left would be that you modify the the files of your package manually and replace all `np.int, np.float` with `int, float`. – Daraan Jan 17 '23 at 18:46