keras无法在Anaconda环境(tensorflow)的ipython中正常import问题

在Ubuntu16.04的Anaconda环境中,使用tensorflow1.6时遇到在ipython中导入keras失败的问题。通过安装ipykernel、查找并修改ipython启动文件中的Python解释器路径,以及更新ipython的kernel配置,可以解决这个问题。重启或注销后,keras能在ipython中正常导入。

该问题处理之前的状态:

环境:Ubuntu16.04 + Anaconda + tensorflow1.6(使用python3.6)

状态展示

这里写图片描述

在ipython中执行完import keras之后,出现“no moudle named keras”

处理方法

1、安装ipykernel

conda install ipykernel

2、找到ipython的启动文件

which ipython
这里写图片描述

3、得到正确的python解释器路径

source activate tensorflow
python
import sys
sys.executable
这里写图片描述

4、修改ipython启动文件的内容

sudo vim /home/bit-zhu/anac

AttributeError Traceback (most recent call last) <ipython-input-8-8f7733e9c222> in <module> ----> 1 import tensorflow as tf 2 import matplotlib.pyplot as plt 3 import numpy as np F:\Anaconda\lib\site-packages\tensorflow\__init__.py in <module> 36 import typing as _typing 37 ---> 38 from tensorflow.python.tools import module_util as _module_util 39 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader 40 F:\Anaconda\lib\site-packages\tensorflow\python\__init__.py in <module> 43 from tensorflow.python import distribute 44 # from tensorflow.python import keras ---> 45 from tensorflow.python.feature_column import feature_column_lib as feature_column 46 # from tensorflow.python.layers import layers 47 from tensorflow.python.module import module F:\Anaconda\lib\site-packages\tensorflow\python\feature_column\feature_column_lib.py in <module> 16 17 # pylint: disable=unused-import,line-too-long,wildcard-import,g-bad-import-order ---> 18 from tensorflow.python.feature_column.feature_column import * 19 from tensorflow.python.feature_column.feature_column_v2 import * 20 from tensorflow.python.feature_column.sequence_feature_column import * F:\Anaconda\lib\site-packages\tensorflow\python\feature_column\feature_column.py in <module> 141 from tensorflow.python.framework import sparse_tensor as sparse_tensor_lib 142 from tensorflow.python.framework import tensor_shape --> 143 from tensorflow.python.layers import base 144 from tensorflow.python.ops import array_ops 145 from tensorflow.python.ops import array_ops_stack F:\Anaconda\lib\site-packages\tensorflow\python\layers\base.py in <module> 14 # ============================================================================= 15 """Contains the base Layer class, from which all layers inherit.""" ---> 16 from tensorflow.python.keras.legacy_tf_layers import base 17 18 InputSpec = base.InputSpec F:\Anaconda\lib\site-packages\tensorflow\python\keras\__init__.py in <module> 23 24 # See b/110718070#comment18 for more details about this import. ---> 25 from tensorflow.python.keras import models 26 27 from tensorflow.python.keras.engine.input_layer import Input F:\Anaconda\lib\site-packages\tensorflow\python\keras\models.py in <module> 20 from tensorflow.python.keras import metrics as metrics_module 21 from tensorflow.python.keras import optimizer_v1 ---> 22 from tensorflow.python.keras.engine import functional 23 from tensorflow.python.keras.engine import sequential 24 from tensorflow.python.keras.engine import training F:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\functional.py in <module> 30 from tensorflow.python.keras.engine import input_spec 31 from tensorflow.python.keras.engine import node as node_module ---> 32 from tensorflow.python.keras.engine import training as training_lib 33 from tensorflow.python.keras.engine import training_utils 34 from tensorflow.python.keras.saving.saved_model import network_serialization F:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\training.py in <module> 51 from tensorflow.python.keras.mixed_precision import loss_scale_optimizer as lso 52 from tensorflow.python.keras.mixed_precision import policy ---> 53 from tensorflow.python.keras.saving import hdf5_format 54 from tensorflow.python.keras.saving import save 55 from tensorflow.python.keras.saving import saving_utils F:\Anaconda\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py in <module> 35 # pylint: disable=g-import-not-at-top 36 try: ---> 37 import h5py 38 HDF5_OBJECT_HEADER_LIMIT = 64512 39 except ImportError: F:\Anaconda\lib\site-packages\h5py\__init__.py in <module> 44 _errors.silence_errors() 45 ---> 46 from ._conv import register_converters as _register_converters 47 _register_converters() 48 h5py\h5t.pxd in init h5py._conv() h5py\h5t.pyx in init h5py.h5t() F:\Anaconda\lib\site-packages\numpy\__init__.py in __getattr__(attr) 318 return Tester 319 --> 320 raise AttributeError("module {!r} has no attribute " 321 "{!r}".format(__name__, attr)) 322 AttributeError: module 'numpy' has no attribute 'typeDict'
最新发布
11-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值