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 https://www.tensorflow.org/api_docs/python/tf/contrib/keras/preprocessing.

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 aryya
• 7,460 points
6,297 views

1 answer to this question.

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,720 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 21, 2019 in Python by Mohammad
• 3,230 points
832 views
+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,890 points
20,009 views
+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,440 points
1,306 views
+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
28,835 views
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,720 points
2,655 views
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,720 points
2,339 views
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
3,458 views
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
• 58,020 points
24,220 views
+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 4, 2018 in Python by charlie_brown
• 7,720 points
13,544 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP