Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 421
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 5
Kenil Vasani
Asked: December 11, 20202020-12-11T20:36:12+00:00 2020-12-11T20:36:12+00:00In: Python

ImportError: cannot import name np_utils

  • 5

I’m trying to run the following example from keras

but I get this error:

ImportError
Traceback (most recent call last)
<ipython-input-58-50de27eea0f8> in <module>()   
      8 import numpy as np  
      9 import matplotlib.pyplot as plt  
---> 10 from keras.models import Sequential  
     11 from keras.layers import Dense, LSTM  
     12   

/usr/local/lib/python2.7/dist-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  

/usr/local/lib/python2.7/dist-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’m using Ubuntu and I installed keras with:

sudo pip install keras 

This question was already asked but there was no answer:
Keras: Cannot Import Name np_utils

keraspython
  • 1 1 Answer
  • 8 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Rohit Patel

      Rohit Patel

      • 0 Questions
      • 98 Answers
      • 0 Best Answers
      • 0 Points
      View Profile
      Best Answer
      Rohit Patel
      2020-12-11T20:35:26+00:00Added an answer on December 11, 2020 at 8:35 pm

      np_utils is a separate package (and a keras dependency – which doesn’t get install with it). Can be installed using pip:

      pip install np_utils
      

      using – Keras==2.0.6


      Suggestion:
      For some odd (and still unknown) reasons, even after installing the import

      from keras.utils.np_utils import to_categorical
      

      didn’t work – I had to restart the notebook (first restart even didn’t work), and once it worked, I got stuck again for same import call (gave exception for no module named tensorflow) – as in utils there’s another import from . import conv_utils, which required the tensorflow.

      I did try installing tensorflow using pip install tensorflow gave:

      Could not find a version that satisfies the requirement tensorflow
      (from versions: ) No matching distribution found for tensorflow

      even this gist didn’t work for me.


      Finally, I installed Anaconda – which have all the scientific packages (numpy, scipy, scikit-learn,..) pre-installed. Installed keras:

      conda install keras
      

      Best thing was, it even installed tensorflow as its dependency.

      • 3
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      ERROR: torch has an invalid wheel, .dist-info directory not found

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com