初遇Tensorflow问题

# ===================  1 ==========================

tensorflow成功安装无法导入。

百度、fq没找到解决办法。

无奈学艺不精,费时费力,只有one by one

报错:

>>> import tensorflowTraceback (most recent call last):  File "", line 1, inFile "/home/hx/anaconda2/lib/python2.7/tensorflow/__init__.py", line 24, infrom tensorflow.python import *  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/__init__.py", line 63, infrom tensorflow.python.framework.framework_lib import *  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/framework/framework_lib.py", line 100, infrom tensorflow.python.framework.subscribe import subscribe  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/framework/subscribe.py", line 26, infrom tensorflow.python.ops import variables  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/ops/variables.py", line 26, infrom tensorflow.python.ops import control_flow_ops  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/ops/control_flow_ops.py", line 70, infrom tensorflow.python.ops import tensor_array_ops  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/ops/tensor_array_ops.py", line 33, infrom tensorflow.python.util import tf_should_use  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/util/tf_should_use.py", line 28, infrom backports import weakref  # pylint: disable=g-bad-import-order

ImportError: cannot import name weakref

再次导入报错:

>>> import tensorflowTraceback (most recent call last):  File "", line 1, inFile "/home/hx/anaconda2/lib/python2.7/tensorflow/__init__.py", line 24, infrom tensorflow.python import *  File "/home/hx/anaconda2/lib/python2.7/tensorflow/python/__init__.py", line 49, infrom tensorflow.python import pywrap_tensorflow

ImportError: cannot import name pywrap_tensorflow

解决办法:

在终端输入:

$ vim .bashrc

加入环境路径:

#export PYTHONPATH=/your space/anaconda2/lib/python2.7:$PYTHONPAT

至此:可一并解决激活或不激活tensorflow环境导入问题

如果在不激活tensorflow环境时无法:import tensorflow

则需将:

/your space/anaconda2/envs/tensorflow/lib/python2.7/site-packages

所有文件复制到:

/your space/anaconda2/lib/python2.7/site-packages

# ===================  2 ==========================

在执行:

tensorboard --logdir='logs/'

报错:

Fatal Python error: Py_Initialize: Unable to get the locale encoding

File "/home/hx/anaconda2/lib/python2.7/encodings/__init__.py", line 123

raise CodecRegistryError,\

SyntaxError: invalid syntax

Aborted (core dumped)

解决:

我是在系统环境下执行的tensorboard --logdir='logs/',可能由于路径问题。

激活tensorflow环境:source activate tensorflow

再执行tensorboard --logdir='logs/'

之后在浏览器输入:http://0.0.0.0:6006

便可访问。

#===================================================

你可能感兴趣的:(初遇Tensorflow问题)