catboost: Unable to import _catboost when installed from wheel / py36 / new conda env

With a freshly created empty conda environment with numpy and six preinstalled (Linux / Python 3.6 / catboost 0.6.3):

$ conda install -y numpy
The following NEW packages will be INSTALLED:
    mkl:   2017.0.3-0
    numpy: 1.13.1-py36_0
Linking packages ...

$ pip install catboost
Collecting catboost
  Using cached catboost-0.6.3-cp36-none-manylinux1_x86_64.whl
Requirement already satisfied: numpy in ./env/lib/python3.6/site-packages (from catboost)
Requirement already satisfied: six in ./env/lib/python3.6/site-packages (from catboost)
Installing collected packages: catboost
Successfully installed catboost-0.6.3

Now trying it out; looks like this one’s the actual problem:

>>> from catboost import _catboost
AttributeError: type object '_catboost._FloatArrayWrapper' has no attribute '__reduce_cython__'

And this is just a consequence of the extension module not being fully imported:

>>> from catboost import CatBoost
>>> CatBoost()
NameError                                 Traceback (most recent call last)
./env/lib/python3.6/site-packages/catboost/core.py in __init__(self, params, model_file)
    531         self._check_params(params)
    532         params = self._params_type_cast(params)
>>> 533         super(CatBoost, self).__init__(params)
    534         if model_file is not None:
    535             self.load_model(model_file)
_catboost.pyx in _catboost._CatBoostBase.__init__()
_catboost.pyx in _catboost._CatBoostBase._check_train_params()
_catboost.pyx in _catboost._PreprocessParams.__init__()
NameError: name 'dumps' is not defined

Potentially related issues that I’ve managed to find, seems like it has to do with Cython / auto-pickling:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I was trying to import catboost on Jupyterlab. In my code I have,

import catboost
from catboost import CatBoostClassifier, Pool, cv

Then, I get AttributeError

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-141-6cf651ad4ca4> in <module>
     30 from sklearn.linear_model import LinearRegression, LogisticRegression, SGDClassifier
     31 from sklearn.tree import DecisionTreeClassifier
---> 32 from catboost import CatBoostClassifier, Pool, cv
     33 #from catboost import CatBoost
     34 

/usr/local/lib/python3.7/site-packages/catboost/__init__.py in <module>
----> 1 from .core import FeaturesData, EFstrType, Pool, CatBoost, CatBoostClassifier, CatBoostRegressor, CatBoostError, cv, train, sum_models  # noqa
      2 from .version import VERSION as __version__  # noqa
      3 __all__ = ['FeaturesData', 'EFstrType', 'Pool', 'CatBoost', 'CatBoostClassifier', 'CatBoostRegressor', 'CatBoostError', 'CatboostError', 'cv', 'train', 'sum_models']
      4 
      5 # API compatibility alias.

/usr/local/lib/python3.7/site-packages/catboost/core.py in <module>
     58 
     59 
---> 60 _catboost = get_catboost_bin_module()
     61 _PoolBase = _catboost._PoolBase
     62 _CatBoost = _catboost._CatBoost

/usr/local/lib/python3.7/site-packages/catboost/core.py in get_catboost_bin_module()
     49     for so_path in so_paths:
     50         try:
---> 51             loaded_catboost = imp.load_dynamic('_catboost', so_path)
     52             sys.modules['catboost._catboost'] = loaded_catboost
     53             return loaded_catboost

/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py in load_dynamic(name, path, file)
    341         spec = importlib.machinery.ModuleSpec(
    342             name=name, loader=loader, origin=path)
--> 343         return _load(spec)
    344 
    345 else:

_catboost.pyx in init _catboost()

AttributeError: type object '_catboost._FloatArrayWrapper' has no attribute '__reduce_cython__'

It worked for me as well by rebooting jupyter.

So, i installed catboost by conda install, and after jupyter rebooting catboost can import.

I installed catboost and came across this error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-0dc2ed2a0f5e> in <module>
      1 import numpy as np
      2 import pandas as pd
----> 3 import catboost

~\AppData\Roaming\Python\Python37\site-packages\catboost\__init__.py in <module>
----> 1 from .core import FeaturesData, EFstrType, Pool, CatBoost, CatBoostClassifier, CatBoostRegressor, CatBoostError, cv, train, sum_models, _have_equal_features  # noqa
      2 from .version import VERSION as __version__  # noqa
      3 __all__ = ['FeaturesData', 'EFstrType', 'Pool', 'CatBoost', 'CatBoostClassifier', 'CatBoostRegressor', 'CatBoostError', 'CatboostError', 'cv', 'train', 'sum_models', '_have_equal_features']
      4 
      5 # API compatibility alias.

~\AppData\Roaming\Python\Python37\site-packages\catboost\core.py in <module>
     60 
     61 
---> 62 _catboost = get_catboost_bin_module()
     63 _PoolBase = _catboost._PoolBase
     64 _CatBoost = _catboost._CatBoost

~\AppData\Roaming\Python\Python37\site-packages\catboost\core.py in get_catboost_bin_module()
     51     for so_path in so_paths:
     52         try:
---> 53             loaded_catboost = imp.load_dynamic('_catboost', so_path)
     54             sys.modules['catboost._catboost'] = loaded_catboost
     55             return loaded_catboost

C:\ProgramData\Anaconda3\lib\imp.py in load_dynamic(name, path, file)
    340         spec = importlib.machinery.ModuleSpec(
    341             name=name, loader=loader, origin=path)
--> 342         return _load(spec)
    343 
    344 else:

_catboost.pyx in init _catboost()

AttributeError: type object '_catboost.Py_ITypedSequencePtr' has no attribute '__reduce_cython__'

Got the same

@kizill Can confirm that with 0.8 the bug is apparently gone (testing it on the same environment as reported initially, Linux, 3.6), this issue should probably be closed.