Why I receive ImportError: cannot import name 'just_fix_windows_console' from 'colorama'?
Question:
I have to use BayesianOptimization for hyper parameter tuning for neural networks, for the same when I’m importing it using, from bayes_opt import BayesianOptimization
, the following error is obtained
`ImportError Traceback (most recent call last)
~AppDataLocalTempipykernel_288961719632484.py in <module>
----> 1 from bayes_opt import BayesianOptimization
~anaconda3libsite-packagesbayes_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
~anaconda3libsite-packagesbayes_optbayesian_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
~anaconda3libsite-packagesbayes_opttarget_space.py in <module>
2
3 import numpy as np
----> 4 from .util import ensure_rng, NotUniqueError
5 from .util import Colours
6
~anaconda3libsite-packagesbayes_optutil.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' (C:Userssaigaanaconda3libsite-packagescolorama__init__.py)
`
- I have tried importing ‘colorama’, and other modules in it, which was working, but this name isn’t.
- Also BayesianOptimization can be directly imported, using
import BayesianOptimization
but I need to call BayesianOPtimization in the program later using
gbm_bo = BayesianOptimization(gbm_cl_bo, params_gbm, random_state=111)
where gbm_cl_bo are functions defined. But then, the below given error is coming.
TypeError: 'module' object is not callable
So, inorder to avoid this I think I need to call BayesianOptimization from a parent directory. For the same I have also tried the following code : "from .BayesianOptimization import BayesianOptimization", but received the error as
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~AppDataLocalTempipykernel_28896572044167.py in <module>
----> 1 from .BayesianOptimization import BayesianOptimization
ImportError: attempted relative import with no known parent package
- So how to fix the above import error?
- Otherwise, is there an alternate way of calling BayesianOptimization, so as not to get the error "’module’ object is not callable".
Answers:
Based on the changelog for colorama, that function was added in the latest version of the library, 0.4.6.
Make sure you have that version installed, with e.g. pip install -U colorama
.
In my case I am using poetry as a package manager, I tried
poetry add colorama==0.4.4
Which also downgraded bayesian-optimisation
- Updating colorama (0.4.6 -> 0.4.4)
- Updating bayesian-optimization (1.4.2 -> 1.4.1)
I made some progress to a new unrelated error.
I had the same issue. The colorama package requires a python version above 3.6. Otherwise colorama=0.4.5 is installed and, leading to a failure of a sucessful run. Therefore during creating the environment install a newer python version
I have to use BayesianOptimization for hyper parameter tuning for neural networks, for the same when I’m importing it using, from bayes_opt import BayesianOptimization
, the following error is obtained
`ImportError Traceback (most recent call last)
~AppDataLocalTempipykernel_288961719632484.py in <module>
----> 1 from bayes_opt import BayesianOptimization
~anaconda3libsite-packagesbayes_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
~anaconda3libsite-packagesbayes_optbayesian_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
~anaconda3libsite-packagesbayes_opttarget_space.py in <module>
2
3 import numpy as np
----> 4 from .util import ensure_rng, NotUniqueError
5 from .util import Colours
6
~anaconda3libsite-packagesbayes_optutil.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' (C:Userssaigaanaconda3libsite-packagescolorama__init__.py)
`
- I have tried importing ‘colorama’, and other modules in it, which was working, but this name isn’t.
- Also BayesianOptimization can be directly imported, using
import BayesianOptimization
but I need to call BayesianOPtimization in the program later using
gbm_bo = BayesianOptimization(gbm_cl_bo, params_gbm, random_state=111)
where gbm_cl_bo are functions defined. But then, the below given error is coming.
TypeError: 'module' object is not callable
So, inorder to avoid this I think I need to call BayesianOptimization from a parent directory. For the same I have also tried the following code : "from .BayesianOptimization import BayesianOptimization", but received the error as
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~AppDataLocalTempipykernel_28896572044167.py in <module>
----> 1 from .BayesianOptimization import BayesianOptimization
ImportError: attempted relative import with no known parent package
- So how to fix the above import error?
- Otherwise, is there an alternate way of calling BayesianOptimization, so as not to get the error "’module’ object is not callable".
Based on the changelog for colorama, that function was added in the latest version of the library, 0.4.6.
Make sure you have that version installed, with e.g. pip install -U colorama
.
In my case I am using poetry as a package manager, I tried
poetry add colorama==0.4.4
Which also downgraded bayesian-optimisation
- Updating colorama (0.4.6 -> 0.4.4)
- Updating bayesian-optimization (1.4.2 -> 1.4.1)
I made some progress to a new unrelated error.
I had the same issue. The colorama package requires a python version above 3.6. Otherwise colorama=0.4.5 is installed and, leading to a failure of a sucessful run. Therefore during creating the environment install a newer python version