ImportError: cannot import name np_utils

See original GitHub issue

Hi all,

I installed Keras with Anaconda on 2.7 python environement.

When I do the following : import keras : I get the following error and it stack. I tried everything I could find on stack and google without any help. I even tried installing it on a freshly installed environement without any improvements.

----> 1 import keras

/home/mohamed/.local/lib/python2.7/site-packages/keras/init.py in <module>() 1 from future import absolute_import 2 ----> 3 from . import utils 4 from . import activations 5 from . import applications

/home/mohamed/.local/lib/python2.7/site-packages/keras/utils/init.py in <module>() 1 from future import absolute_import ----> 2 from . import np_utils 3 from . import generic_utils 4 from . import data_utils 5 from . import io_utils

ImportError: cannot import name np_utils

I checked the files. I am pretty sure they are there.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
jkrathorecommented, Nov 22, 2019

try this from tensorflow.python.keras.utils import np_utils

7reactions
fcholletcommented, Apr 10, 2018

In the public API, you cannot access np_util (it’s internal). You are supposed to access utilities via the utils module, e.g.

from keras import utils

utils.to_categorical(...)
Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: cannot import name np_utils - Stack Overflow
I ran into the same issue. You need to do pip install np_utils and then restart your terminal.
Read more >
cannot import name 'np_utils' from 'tensorflow.keras.utils' 的 ...
由于keras版本的升级,在__init__.py里可以看到,包的迁移导致了在anaconda中就算安装了np_utils包,还是导入不进来。以我要使用到的to_categorical为例。
Read more >
cannot import name 'to_categorical' from 'keras.utils' (Solved)
importerror : cannot import name 'to_categorical' from 'keras.utils' error occurs because of importing keras.utils in the place of tensorflow.keras.utils ...
Read more >
cannot import name 'np_utils' from 'tensorflow.keras.utils' 的问题
出现以下问题: cannot import name 'np_utils' from 'tensorflow.keras.utils' (C:\Software\Anaconda3\envs\machine\lib\site... 查看原文 · Embedding. = model.predict ...
Read more >
解决ImportError: cannot import name 'np_utils' from 'tensorflow ...
解决ImportError: cannot import name 'np_utils' from 'tensorflow.keras.utils'在构建语料库词汇表时使用了from tensorflow.keras.utils import np_utils出现下列 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found