ColtAllen / btyd

Buy Till You Die and Customer Lifetime Value statistical models in Python.
https://btyd.readthedocs.io/
Apache License 2.0
114 stars 9 forks source link

ImportError: cannot import name 'minimize' from 'scipy.optimize' (unknown location) #81

Closed SSMK-wq closed 1 year ago

SSMK-wq commented 1 year ago

I am using python 3.8.8 in windows 10 with btyd 0.1b3.

While my btyd package is installed successfully, I get the below error when I try to import the btyd package in my jupyter notebook

ImportError                               Traceback (most recent call last)
<ipython-input-1-8ac04f5820c7> in <module>
     10 from math import sqrt
     11 import pycaret
---> 12 import btyd
     13 from btyd import *

~\AppData\Roaming\Python\Python38\site-packages\btyd\__init__.py in <module>
      1 import warnings
      2 
----> 3 from .fitters import BaseFitter
      4 from .fitters.beta_geo_fitter import BetaGeoFitter
      5 from .fitters.beta_geo_beta_binom_fitter import BetaGeoBetaBinomFitter

~\AppData\Roaming\Python\Python38\site-packages\btyd\fitters\__init__.py in <module>
      8 import pandas as pd
      9 from textwrap import dedent
---> 10 from scipy.optimize import minimize
     11 from autograd import value_and_grad, hessian
     12 from ..utils import _save_obj_without_attr, ConvergenceError

ImportError: cannot import name 'minimize' from 'scipy.optimize' (unknown location)

How to import btyd package successfully without any error?

my pip show command returns the below output

pip show scipy

Name: scipy
Version: 1.8.1
Summary: SciPy: Scientific Library for Python
Home-page: https://www.scipy.org
Author: None
Author-email: None
License: BSD
Location: c:\users\test\anaconda3\lib\site-packages
Requires: numpy
Required-by: ziln-cltv, yellowbrick, xgboost, xarray-einstats, umap-learn, scikit-optimize, scikit-learn, salib, pynndescent, pymc, pyLDAvis, pycaret, phik, pandas-profiling, mlxtend, mlflow, missingno, kmodes, imbalanced-learn, ImageHash, hyperopt, gensim, feature-engine, catboost, Boruta, arviz, aesara, aeppl, statsmodels, seaborn, scikit-plot, scikit-image, pyod, optuna, lightgbm, category-encoders

my pip show for btyd looks like below

Name: btyd
Version: 0.1b3
Summary: Buy Till You Die and Customer Lifetime Value statistical models in Python.
Home-page: None
Author: Colt Allen
Author-email: None
License: Apache 2.0
Location: c:\users\users\anaconda3\lib\site-packages
Requires: autograd, pymc, numpy
Required-by:

When I degrade the scipy to 1.6.1, I get the below warning and error in jupyter notebook

WARNING (aesara.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
WARNING (aesara.configdefaults): g++ not detected!  Aesara will be unable to compile C-implementations and will default to Python. Performance may be severely degraded. To remove this warning, set Aesara flags cxx to an empty string.
---------------------------------------------------------------------------
NoSectionError                            Traceback (most recent call last)
~\AppData\Roaming\Python\Python38\site-packages\aesara\configparser.py in fetch_val_for_key(self, key, delete_key)
    236             try:
--> 237                 return self._aesara_cfg.get(section, option)
    238             except InterpolationError:

~\Anaconda3\lib\configparser.py in get(self, section, option, raw, vars, fallback)
    780         try:
--> 781             d = self._unify_values(section, vars)
    782         except NoSectionError:

~\Anaconda3\lib\configparser.py in _unify_values(self, section, vars)
   1148             if section != self.default_section:
-> 1149                 raise NoSectionError(section) from None
   1150         # Update with the entry specific variables

NoSectionError: No section: 'blas'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~\AppData\Roaming\Python\Python38\site-packages\aesara\configparser.py in __get__(self, cls, type_, delete_key)
    352             try:
--> 353                 val_str = cls.fetch_val_for_key(self.name, delete_key=delete_key)
    354                 self.is_default = False

~\AppData\Roaming\Python\Python38\site-packages\aesara\configparser.py in fetch_val_for_key(self, key, delete_key)
    240         except (NoOptionError, NoSectionError):
--> 241             raise KeyError(key)
    242 

KeyError: 'blas__ldflags'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-1-8ac04f5820c7> in <module>
     10 from math import sqrt
     11 import pycaret
---> 12 import btyd
     13 from btyd import *

~\Anaconda3\lib\site-packages\btyd\__init__.py in <module>
      8 from .fitters.gamma_gamma_fitter import GammaGammaFitter
      9 from .fitters.beta_geo_covar_fitter import BetaGeoCovarsFitter
---> 10 from .models.beta_geo_model import BetaGeoModel
     11 from .models.mod_beta_geo_model import ModBetaGeoModel
     12 from .models.gamma_gamma_model import GammaGammaModel

~\Anaconda3\lib\site-packages\btyd\models\__init__.py in <module>
     10 import pandas as pd
     11 
---> 12 import pymc as pm
     13 import aesara.tensor as at
     14 import arviz as az

~\AppData\Roaming\Python\Python38\site-packages\pymc\__init__.py in <module>
     45 
     46 
---> 47 __set_compiler_flags()
     48 
     49 from pymc import _version, gp, ode, sampling

~\AppData\Roaming\Python\Python38\site-packages\pymc\__init__.py in __set_compiler_flags()
     28 def __set_compiler_flags():
     29     # Workarounds for Aesara compiler problems on various platforms
---> 30     import aesara
     31 
     32     current = aesara.config.gcc__cxxflags

~\AppData\Roaming\Python\Python38\site-packages\aesara\__init__.py in <module>
    118 
    119 # isort: off
--> 120 from aesara import scalar, tensor
    121 from aesara.compile import (
    122     In,

~\AppData\Roaming\Python\Python38\site-packages\aesara\tensor\__init__.py in <module>
    103 # adds shared-variable constructors
    104 from aesara.tensor import sharedvar  # noqa
--> 105 from aesara.tensor import (  # noqa
    106     blas,
    107     blas_c,

~\AppData\Roaming\Python\Python38\site-packages\aesara\tensor\blas.py in <module>
    160 from aesara.scalar import bool as bool_t
    161 from aesara.tensor import basic as at
--> 162 from aesara.tensor.blas_headers import blas_header_text, blas_header_version
    163 from aesara.tensor.elemwise import DimShuffle, Elemwise
    164 from aesara.tensor.exceptions import NotScalarConstantError

~\AppData\Roaming\Python\Python38\site-packages\aesara\tensor\blas_headers.py in <module>
   1013 
   1014 
-> 1015 if not config.blas__ldflags:
   1016     _logger.warning("Using NumPy C-API based implementation for BLAS functions.")
   1017 

~\AppData\Roaming\Python\Python38\site-packages\aesara\configparser.py in __get__(self, cls, type_, delete_key)
    355             except KeyError:
    356                 if callable(self.default):
--> 357                     val_str = self.default()
    358                 else:
    359                     val_str = self.default

~\AppData\Roaming\Python\Python38\site-packages\aesara\link\c\cmodule.py in default_blas_ldflags()
   2861         if any("mkl" in fl for fl in ret):
   2862             ret.extend(["-lm", "-lm"])
-> 2863         res = try_blas_flag(ret)
   2864         if res:
   2865             if "mkl" in res:

~\AppData\Roaming\Python\Python38\site-packages\aesara\link\c\cmodule.py in try_blas_flag(flags)
   1993     cflags.extend([f"-L{path_wrapper}{d}{path_wrapper}" for d in std_lib_dirs()])
   1994 
-> 1995     res = GCC_compiler.try_compile_tmp(
   1996         test_code, tmp_prefix="try_blas_", flags=cflags, try_run=True
   1997     )

~\AppData\Roaming\Python\Python38\site-packages\aesara\link\c\cmodule.py in try_compile_tmp(cls, src_code, tmp_prefix, flags, try_run, output, comp_args)
   2394             src_code,
   2395             tmp_prefix,
-> 2396             cls.patch_ldflags(flags),
   2397             try_run,
   2398             output,

~\AppData\Roaming\Python\Python38\site-packages\aesara\link\c\cmodule.py in patch_ldflags(flag_list)
   2432         if not libs:
   2433             return flag_list
-> 2434         libs = GCC_compiler.linking_patch(lib_dirs, libs)
   2435         for flag_idx, lib in zip(flag_idxs, libs):
   2436             flag_list[flag_idx] = lib

~\AppData\Roaming\Python\Python38\site-packages\aesara\link\c\cmodule.py in linking_patch(lib_dirs, libs)
   2453                 windows_styled_libs = [
   2454                     fname
-> 2455                     for fname in os.listdir(lib_dir)
   2456                     if not (os.path.isdir(os.path.join(lib_dir, fname)))
   2457                     and fname.split(".")[0] == lib

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\numpy\\build\\openblas_info'
SSMK-wq commented 1 year ago

Closing this issue as a fresh install after clean up of environment solved the issue. Not sure whether it is the best way to solve this problem but solved for now. So, closing this