当我尝试运行此
时import keras
我正在关注错误:
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'
我已经通过以下命令安装了Theano
,Tensorflow
和Keras
:
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
以上命令正常工作。
但我犯了错误。我该如何解决这个错误?
答案 0 :(得分:1)
要确保已安装所有库,可以将文本文件与以下内容一起使用:
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
然后使用pip进行安装:
pip install -r requirements.txt
或
pip3 install -r requirements.txt
如果您有多个安装,将安装所有库以在同一python版本中使用。
答案 1 :(得分:0)
您的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
创建并激活了一个名为tensorflow的虚拟环境。请注意(tensorflow)
之前的Rezwans-iMac
,表明您在新创建的虚拟环境中。由于tensorflow仅安装在此虚拟环境中,因此您需要使用
source activate tensorflow
每次您想使用张量流。您还需要安装要在此环境中使用的其他软件包。
还配置您的IDE以使用.../anaconda/env/tensorflow/bin/python
中的解释器