When I am trying to run this
import keras
I am getting following error:
Traceback (most recent call last):
File "<ipython-input-1-c74e2bd4ca71>", line 1, in <module>
import keras
File "/Users/rezwan/anaconda/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
from . import utils
File "/Users/rezwan/anaconda/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
File "/Users/rezwan/anaconda/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 3, in <module>
from .. import backend as K
File "/Users/rezwan/anaconda/lib/python3.6/site-packages/keras/backend/__init__.py", line 83, in <module>
from .tensorflow_backend import *
File "/Users/rezwan/anaconda/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2, in <module>
from tensorflow.python.training import moving_averages
ModuleNotFoundError: No module named 'tensorflow.python.training'
Already I have installed Theano
, Tensorflow
and Keras
through the following commands:
Theano:
Rezwans-iMac:~ rezwan$ pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
Tensorflow:
Rezwans-iMac:~ rezwan$ conda create -n tensorflow python=3.6
Rezwans-iMac:~ rezwan$ source activate tensorflow
(tensorflow) Rezwans-iMac:~ rezwan$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.3.0rc2-py3-none-any.whl
(tensorflow) Rezwans-iMac:~ rezwan$ pip3 install --upgrade $TF_BINARY_URL
Keras:
Rezwans-iMac:~ rezwan$ pip install --upgrade keras
Above commands work properly.
But I am getting above error. How can I solve this error?
To make sure all libraries are installed, you can use a text file with something like this:
jupyter==1.0.0
Keras==2.1.3
numpy==1.15.1
pandas==0.22.0
scikit-learn==0.19.1
scipy==1.0.0
tensorboard==1.10.0
tensorflow==1.10.0
Then use pip to install:
pip install -r requirements.txt
or
pip3 install -r requirements.txt
All libraries will be installed for use in the same python version, in case you have multiple installations.
Your tensorflow installation commands:
Rezwans-iMac:~ rezwan$ conda create -n tensorflow python=3.6
Rezwans-iMac:~ rezwan$ source activate tensorflow
(tensorflow) Rezwans-iMac:~ rezwan$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.3.0rc2-py3-none-any.whl
(tensorflow) Rezwans-iMac:~ rezwan$ pip3 install --upgrade $TF_BINARY_URL
created and activated a virtual environment called tensorflow. Notice the (tensorflow)
before Rezwans-iMac
, indicating that you are inside the newly created virtual environment. Since tensorflow is only installed in this virtual environment, you need to switch into it with
source activate tensorflow
everytime you want to use tensorflow. You will also need to install other packages that you want to use inside this environment.
Also configure your IDE to use the interpreter in .../anaconda/env/tensorflow/bin/python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With