I am having trouble getting tensorflow to work using Jupiter notebooks. I am a complete noob so please keep responses as simple as possible and apologies if this is trivial.
I run the following code in the notebook:
import tensorflow as tf
from tensorflow.python.framework import ops
And get this error message:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-509396287076> in <module>()
1
2 import tensorflow as tf
----> 3 from tensorflow.python.framework import ops
4 from tf_utils import load_dataset, random_mini_batches, convert_to_one_hot, predict
5
ModuleNotFoundError: No module named 'tensorflow.python'
(I originally struggled to get the "import tensorflow as tf" line to work but have resolved that. The code runs fine without the second line...)
Thanks for your help!
Related
I'm currently building a MLP network using the MNIST data set in python. My script can import the mnist module and access the datasets when it's running in the default runtime environment but whenever I try to run it using pypy I get the error
Traceback (most recent call last):
File "LearningProgram.py", line 1, in <module>
from mnist import MNIST
ModuleNotFoundError: No module named 'mnist'
This is how I import mnist if it matters
from mnist import MNIST
import random
import numpy as np
import math
from math import e
from math import log
I've tried uninstalling and reinstalling mnist but it didn't work. I'm also using python 3.8.1
I'm having trouble running my code, here are the results of the error I got :
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-35-d0706627a935> in <module>
1 # import the function to train using spaCy
----> 2 from train_spacy import train_spacy
~\TA\train_spacy.py in <module>
3 from spacy.util import minibatch, compounding
4 from spacy.util import decaying
----> 5 from thinc.neural.optimizers import Adam
6 import random
7 from matplotlib import pyplot as plt
ModuleNotFoundError: No module named 'thinc.neural'
The following are the related modules installed on my OS.
C:\Users\Anonymous>pip list | findstr spacy spacy 3.0.5 spacy-legacy 3.0.1 C:\Users\Anonymous>pip list | findstr thinc thinc 8.0.2
If there are other statements that I have not explained, please ask me, and I ask for your help because I have tried to reinstall the module but are still facing the same error, and I apologize if my language is wrong. Thank you ^ - ^
Since a few versions ago thinc was reorganized. Classes and functions should now be imported from thinc.api.
As you can see, Adam is referenced in https://github.com/explosion/thinc/blob/master/thinc/api.py.
I am trying to move my code from my local machine which uses python 3.6 under an anaconda environment to Google Colab,in order to make use of GPU.
However,some commands are running localy,the same commands don't run in Colab,despite the fact that I have installed all missing modules(everytime I face such an error)
The problem comes at command from dataloader import get_loader,where it throws an error.
It seems that dataloader has problem,because the same error occurs when I just do import dataloader
I have installed with pip dataloader=2.0.0
I have searched a lot but I can't figure out a solution.
Error Message:
ImportError:Traceback (most recent call last)
<ipython-input-57-1c19174cb2f4> in <module>()
----> 1 import dataloader.get_loader
/usr/local/lib/python3.6/dist-packages/dataloader/__init__.py in <module>()
----> 1 from dataloader import read_data_sets
ImportError: cannot import name 'read_data_sets'
I am following this tensorflow tutorial https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html#protobuf-installation-compilation and I am facing some problems when testing the installation.
I installed everything except the COCO API in the tutorial and I am running the object detection demo in jupyter right now. For some reason, I get an error inside the notebook which tells me that there is "No module named 'tensorflow'". Can I still click on Run All or does this error has to be fixed?
Thanks! :)
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ModuleNotFoundError: No module named 'tensorflow'
Okay, for some reasons, I get this error now:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
10 from collections import defaultdict
11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
13 from PIL import Image
14
ModuleNotFoundError: No module named 'matplotlib'
You might be facing the problem of a double version of Python installed on your computer. Jupyter is trying to compile the Tensorflow tutorial file but with the wrong kernel (which should be Python 3).
The same happened to me when trying to run ipynb files in which Tensorflow was included.
So I would first recommend you to do the following:
Check the output of this command in your command line:
jupyter kernelspec list
Then it should output something similar to this: (in case of Windows OS)
python3 c:\python 3.6.8\share\jupyter\kernels\python3
If you find "python2" or any other type of version, you should remove it manually or try by using the command :
jupyter kernelspec remove python_wrong_version
Finally, if the problem is still there you can also check the link https://github.com/jupyter/notebook/issues/397 for further discussions.
When I try to import tensorflow in my Python scripts, I have some weird results. For instance:
import tensorflow
from keras.datasets import imdb
gives me
ModuleNotFoundError
Traceback (most recent call last) <ipython-input-12-25cf0f878919> in <module>()
1 import tensorflow
----> 2 from keras.datasets import imdb
ModuleNotFoundError: No module named 'keras'
If I try:
import tensorflow as tf
from tf.keras.datasets import imdb
I get :
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-9-bd3db3d3567b> in <module>()
1 import tensorflow as tf
----> 2 from tf.keras.datasets import imdb
ModuleNotFoundError: No module named 'tf'
But, if I use :
from tensorflow.keras.datasets import imdb
it works.
I've been googling this for a full hour now, and I still don't understand what I'm doing wrong in the first two scripts.
Thanks
You haven't specified how and where you installed tensorflow, so I could be wrong, but:
(a) it appears that keras is installed with tensorflow, but not in a location that is in the default Python path (hence, you cannot do from keras.datasets import imdb).
(b) this combination:
import tensorflow as tf
from tf.keras.datasets import imdb
is invalid, because from x import y searches for x as a module and not as a symbol in your code's globals (and tf is NOT a module name but a global variable, import tensorflow as tf imports tensorflow and sets tf to point to the module object).
Therefore (unless you fix your install or your PYTHONPATH to make keras visible as a module), you should use this to import keras (or specific symbols from it):
# either this, to access keras.*, e.g., keras.datasets.imdb
import tensorflow.keras as keras
# or this, as you've done in your example
from tensorflow.keras.datasets import imdb