ImportError: No module named 'tensorflow.python'
Solution 1
Uninstall tensorflow:
pip uninstall tensorflow
Then reinstall it:
pip install tensorflow
Solution 2
for me upgrading pip
helped,
pip install --upgrade pip
pip uninstall tensorflow
pip install tensorflow
Solution 3
If you have python 3.6 and up (most likely), a pip3 package will be installed by default. Installing tensorflow using pip3 will make the path of the installation visible to python. So try
pip3 install tensorflow
First response ever, hope it helps!
Solution 4
I have the same problem in Windows 10. Until now I don't know why.
But if I create an virtual environment
cd <your project path>
Install virtualenv
pip install virtualenv
Create the virtual environment
virtualenv <envname>
Activate the env
- Windows Powershell:
.\<envname>\Scripts\activate
- Unix with Bash or zsh:
source <envname>/bin/activate
Then now you install tensorflow
(<envname>) $ pip install tensorflow
And then run Hello World successfully.
*Don't forget that you need to activate or configure everytime the virtual environment jupyter, command-line, etc.
Related videos on Youtube
Rishi Chauhan
Updated on August 31, 2022Comments
-
Rishi Chauhan over 1 year
here i wanna run this code for try neural network with python :
from __future__ import print_function from keras.datasets import mnist from keras.models import Sequential from keras.layers import Activation, Dense from keras.utils import np_utils import tensorflow as tf batch_size = 128 nb_classes = 10 nb_epoch = 12 #input image dimensions img_row, img_cols = 28, 28 #the data, Shuffled and split between train and test sets (X_train, y_train), (X_test, y_test) = mnist.load_data() X_train = X_train.reshape(X_train.shape[0], img_rows * img_cols) X_test = X_test.reshape(X_test.shape[0], img_row * img_cols) X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_text /= 255 print('X_train shape:', X_train.shape) print(X_train_shape[0], 'train samples') print(X_test_shape[0], 'test samples') #convert class vectors to binary category Y_train = np_utils.to_categorical(y_train, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) model = Sequential() model.add(Dense(output_dim = 800, input_dim=X_train.shape[1])) model.add(Activation('sigmoid')) model.add(Dense(nb_classes)) model.add(Actiovation('softmax')) model.compile(loss = 'categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) #crossentropy fungsi galat atau fungsi error dipakai kalo class biner #model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch = nb_poch, verbose=1, validation_data=(X_test, Y_test)) score = model.evaluate(X_test, Y_test, verbose = 0) print('Test Score : ', score[0]) print('Test Accuracy : ', score[1])
at the beginning it must install keras, and success. but when try to run the code at the first the error is :
ImportError : No Moduled Name "tensorflow"
then i install using pip :
pip install tensorflow
after installation i try to run code again, got another message like this :
ImportError : No Moduled Name "tensorflow.python"
Message Error i dont have any idea with the error
-
ppasler over 7 yearsIs it this one: github.com/tensorflow/tensorflow/issues/2885
-
-
Boooooooooms over 5 yearsMy tensorflow is in
help('modules')
list. -
Oshada about 5 yearsexecuting sys.path() gives this error
TypeError: 'list' object is not callable
I think it should besys.path
as it is not a method -
Sumax almost 5 yearsHi @zhaozheng would you be able to explain as to why this occurs; in the original
tensorflow
, why is thetensorflow.python
not properly installed with it. -
Sumant Agnihotri about 4 yearsNot sure if I should be happy or sad that this actually worked
-
Karan over 3 yearssame with me , this method even worked for me even though my error was different :)
-
Matthew Barlowe almost 3 yearsThe OP mentions in the question they have installed tensor flow with pip this answer is not helpful
-
mjkvaak over 2 yearsIf the above does not help, you can try installing non-cached tensorflow by adding
--no-cache-dir
to the last code line. -
Stack crashed over 2 yearsThis 'works' because you most likely had a gpu based tensorflow installed before. By uninstalling and reinstalling you just changed that to cpu. Since there are other dependencies for gpu support, it had issues, now you don't face those issues because it is "downgraded" to cpu.