iskandr/fancyimpute

cannot import name 'Layer' from 'keras.engine'

kkasra12 opened this issue ยท 10 comments

I used pip install fancyimpute to install fancyimpute.
But when I try to import this library, I face this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kasra/.local/lib/python3.8/site-packages/fancyimpute/__init__.py", line 5, in <module>
    from .matrix_factorization import MatrixFactorization
  File "/home/kasra/.local/lib/python3.8/site-packages/fancyimpute/matrix_factorization.py", line 22, in <module>
    from .keras_models import KerasMatrixFactorizer
  File "/home/kasra/.local/lib/python3.8/site-packages/fancyimpute/keras_models.py", line 17, in <module>
    from keras.engine import Layer
ImportError: cannot import name 'Layer' from 'keras.engine' (/home/kasra/.local/lib/python3.8/site-packages/keras/engine/__init__.py)

my Tensorflow and Keras versions are:

>>> import tensorflow
>>> tensorflow.__version__
'2.5.0'
>>> import keras
>>> keras.__version__
'2.5.0'

and I'm using python3.8 on Linux

I have the same error in colab(which uses python3.6)

Hmm. if you change your Keras version to 2.4.3 does it work?

for me changing keras to 2.4.3 does not work, I get different keras and tensorflow related errors

Looks like something changed in Keras or TF. That's what I get for not pinning the version! I'll work on it over the next ~week. Thanks for reporting.

Would you two be so kind as to test the fix? It's in https://github.com/iskandr/fancyimpute/tree/keras so don't use pip install. Just clone, and python setup.py install after installing reqs.

I created a new condo environment, cloned your repository and did a pip install .. Then I imported SoftImpute from fancyimpute import SoftImpute

I got the following error:


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

I'm on a MacBook with Python 3.8

Wow well this is a new one!

with your latest commit ('pinning versions') I don't get errors anymore

This has something to do with CVXPY and TF wanting different numpy versions. I messed around with the install order and I can now locally import tf, np, cvxpy, and fancyimpute. Can you try again please?

Ok fantastic, thanks for checking. I'll bump versions and merge. It should make it up to pypi sometime soon.

your last commit also works