pythonpython-2.7anacondaimblearnsmote

Imbalances-learn module base.py file syntax error coming up while importing SMOTE


I installed imbalanced-learn package using (Python 2.7):

conda install -c conda-forge imbalanced-learn

after installing it, I tried to import SMOTE from the package.

from imblearn.over_sampling import SMOTE

which gave the following error:

File "C:\.conda\envs\py27\lib\site-packages\imblearn\base.py", line 21
    class SamplerMixin(BaseEstimator, metaclass=ABCMeta):
                                               ^
SyntaxError: invalid syntax

can anybody help me in resolving this error or point out if I didn't install the package correctly?


Solution

  • The version that has been installed by conda is not compatible with Python 2 (I advise you to not use it since all datascience package stop to support it).

    You can see it because the syntax to the metaclass should be written in the following manner in Python 2:

    class SamplerMixin(BaseEstimator):
        __metaclass__ = ABC
    

    if I recall correctly