facebookresearch / nevergrad

A Python toolbox for performing gradient-free optimization
https://facebookresearch.github.io/nevergrad/
MIT License
3.97k stars 355 forks source link

cannot import name 'just_fix_windows_console' from 'colorama' #1492

Open kilianmuller opened 1 year ago

kilianmuller commented 1 year ago

Hi, I have just installed nevergrad, but am unable to import it.

This is on Linux.

Steps to reproduce

  1. pip3 install nevergrad -> installs without a problem
  2. In a Jupyter Notebook: import nevergrad as ng

Observed Results

I get the following error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_193577/2768283666.py in <module>
      6 import matplotlib.pyplot as plt
      7 import time
----> 8 import nevergrad as ng

~/.local/lib/python3.10/site-packages/nevergrad/__init__.py in <module>
      6 from .common import typing as typing
      7 from .parametrization import parameter as p
----> 8 from .optimization import optimizerlib as optimizers  # busy namespace, likely to be simplified
      9 from .optimization import families as families
     10 from .optimization import callbacks as callbacks

~/.local/lib/python3.10/site-packages/nevergrad/optimization/__init__.py in <module>
      5 
      6 from .base import Optimizer  # abstract class, for type checking
----> 7 from . import optimizerlib
      8 from .optimizerlib import registry as registry

~/.local/lib/python3.10/site-packages/nevergrad/optimization/optimizerlib.py in <module>
      9 import warnings
     10 import numpy as np
---> 11 from bayes_opt import UtilityFunction
     12 from bayes_opt import BayesianOptimization
     13 import nevergrad.common.typing as tp

~/.local/lib/python3.10/site-packages/bayes_opt/__init__.py in <module>
----> 1 from .bayesian_optimization import BayesianOptimization, Events
      2 from .domain_reduction import SequentialDomainReductionTransformer
      3 from .util import UtilityFunction
      4 from .logger import ScreenLogger, JSONLogger
      5 from .constraint import ConstraintModel

~/.local/lib/python3.10/site-packages/bayes_opt/bayesian_optimization.py in <module>
      3 from bayes_opt.constraint import ConstraintModel
      4 
----> 5 from .target_space import TargetSpace
      6 from .event import Events, DEFAULT_EVENTS
      7 from .logger import _get_default_logger

~/.local/lib/python3.10/site-packages/bayes_opt/target_space.py in <module>
      2 
      3 import numpy as np
----> 4 from .util import ensure_rng, NotUniqueError
      5 from .util import Colours
      6 

~/.local/lib/python3.10/site-packages/bayes_opt/util.py in <module>
      3 from scipy.stats import norm
      4 from scipy.optimize import minimize
----> 5 from colorama import just_fix_windows_console
      6 
      7 

ImportError: cannot import name 'just_fix_windows_console' from 'colorama' (/usr/lib/python3/dist-packages/colorama/__init__.py)

I did find this related message on StackOverflow: https://stackoverflow.com/questions/74654425/why-i-receive-importerror-cannot-import-name-just-fix-windows-console-from-c In it they say:

Based on the changelog for colorama, that function was added in the latest version of the library, 0.4.6.

I tried installing the latest version of colorama, but received the same error message when trying to import.

kilianmuller commented 1 year ago

I managed to fix the issue by downgrading colorama from version 0.4.6 to 0.4.4, and bayesian_optimization from version 1.4.2 to 1.4.0:

yuntichen commented 3 months ago

Hi I also got this error message. Could anyone help me how to fix it?

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[13], line 22
     20 import os
     21 #import BayesianOptimization
---> 22 from bayes_opt import BayesianOptimization, UtilityFunction
     23 #from bayes_opt import BayesianOptimization
     24 from colorama import Fore

File ~/.local/lib/python3.9/site-packages/bayes_opt/__init__.py:1
----> 1 from .bayesian_optimization import BayesianOptimization, Events
      2 from .domain_reduction import SequentialDomainReductionTransformer
      3 from .util import UtilityFunction

File ~/.local/lib/python3.9/site-packages/bayes_opt/bayesian_optimization.py:5
      1 import warnings
      3 from bayes_opt.constraint import ConstraintModel
----> 5 from .target_space import TargetSpace
      6 from .event import Events, DEFAULT_EVENTS
      7 from .logger import _get_default_logger

File ~/.local/lib/python3.9/site-packages/bayes_opt/target_space.py:4
      1 import warnings
      3 import numpy as np
----> 4 from .util import ensure_rng, NotUniqueError
      5 from .util import Colours
      8 def _hashable(x):

File ~/.local/lib/python3.9/site-packages/bayes_opt/util.py:5
      3 from scipy.stats import norm
      4 from scipy.optimize import minimize
----> 5 from colorama import just_fix_windows_console
      8 def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000, n_iter=10):
      9     """
     10     A function to find the maximum of the acquisition function
     11 
   (...)
     44     :return: x_max, The arg max of the acquisition function.
     45     """

ImportError: cannot import name 'just_fix_windows_console' from 'colorama' (/home/gridsan/ychen1/.local/lib/python3.9/site-packages/colorama/__init__.py)