How can I import tensorflow libraries in my Python code?

0 votes

A very basic question.

I am trying to install tensorflow library in Anaconda python(spyder).

import tf.contrib.keras.preprocessing

Its is giving me error as "No module found". I also tried import tensorflow.contrib.keras.preprocessing

I also tried from tf.contrib.keras.preprocessing.text import Tokenizer.

This also doesnt work

However I verified this in the tensorflow website, and it is present. The link to the library is

I tried to pip and conda install. But that also throwing out error.

From anaconda prompt i typed this:

activate tensorflow 
pip install tf.contrib.keras.preprocessing
conda install tf.contrib.keras.preprocessing

Is there anything i miss out, Please correct me.

Dec 31, 2018 in Python by ariaholic
• 7,320 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You are doing it wrong as tf is not the name of the tensorflow module but an alias in the tutorials.

import tensorflow as tf

Thus try this:

from tensorflow.contrib.keras.preprocessing.text import Tokenizer

From your comments it seems that the module might not be installed so you can check in the list of installed packages:

conda list

If not present, install it with pip. Follow the doc.

answered Dec 31, 2018 by charlie_brown
• 7,710 points

Related Questions In Python

0 votes
1 answer

how can i import the tensorflow library in python?

to import the tensorflow library in your ...READ MORE

answered May 20 in Python by Mohammad
• 1,400 points
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,670 points
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,420 points
+2 votes
6 answers

How can I change directory or "cd" in Python?

Context Manager: cd import os class cd:     """Context manager for ...READ MORE

answered Oct 18, 2018 in Python by Nabarupa
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
0 votes
1 answer

How can I check for NaN in Python?

math.isnan() Checks if the float x is a ...READ MORE

answered Aug 16, 2018 in Python by Priyaj
• 56,140 points
0 votes
1 answer
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.