TensorFlow包中包含一个名为mnist.py
的帮助器module。我已经验证我的计算机上存在该文件,并手动将目录添加到sys.path
。当我尝试导入模块时,python似乎无法找到它。我可以import tensorflow as tf
就好了,但是python似乎正在寻找错误目录中的模块,尽管我明确地给出了正确的位置:
>>> import tensorflow.contrib.learn.python.learn.datasets.mnist
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/__init__.py", line 25, in <module>
from tensorflow.contrib import cudnn_rnn
File "/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/__init__.py", line 21, in <module>
from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnGRU
File "/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py", line 28, in <module>
resource_loader.get_path_to_datafile("_cudnn_rnn_ops.so"))
File "/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/util/loader.py", line 42, in load_op_library
ret = load_library.load_op_library(path)
File "/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/load_library.py", line 64, in load_op_library
None, None, error_msg, error_code)
tensorflow.python.framework.errors_impl.NotFoundError: /home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/python/ops/_cudnn_rnn_ops.so: cannot open shared object file: No such file or directory
验证文件
ls -l ~/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets
total 44
-rw-rw-r-- 2 rh rh 4660 Dec 1 12:09 base.py
drwxrwxr-x 3 rh rh 4096 Jan 12 19:57 data
-rw-rw-r-- 2 rh rh 2126 Dec 1 12:09 __init__.py
-rw-rw-r-- 2 rh rh 1334 Dec 1 12:09 load_csv_test.py
-rw-rw-r-- 2 rh rh 8308 Dec 1 12:09 mnist.py
-rw-rw-r-- 2 rh rh 1317 Dec 1 12:09 produce_small_datasets.py
drwxrwxr-x 2 rh rh 4096 Jan 12 19:57 __pycache__
-rw-rw-r-- 2 rh rh 2745 Dec 1 12:09 text_datasets.py
验证路径
>>> sys.path
['', '/home/rh/Applications/Anaconda/anaconda3/lib/python35.zip',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/plat-linux',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/lib-dynload',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg',
'/home/rh/Applications/Anaconda/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets']
Tensorflow信息
$ conda list | grep tensorflow
tensorflow 0.12.0rc0 py35_0 jjhelmus
只有1个Python环境
$ conda env list
# conda environments:
#
root * /home/rh/Applications/Anaconda/anaconda3
$ type -p python
/home/rh/Applications/Anaconda/anaconda3/bin/python
我的源代码来自一个在OSX上完美运行的tensorflow教程,关于Ubuntu安装/环境的一些问题很糟糕。 我一直在打这个问题一段时间没有成功。这个相关的question也没有解决这个问题。有什么建议吗?
答案 0 :(得分:0)
找到了这个related question和@ gunan评论答案的线索。
虽然有问题的机器没有python-gpu接口,但python仍在寻找cudnn文件。 tensorflow 0.12.0rc0
(从私有repo安装)提供gpu support by default,我无法通过重置环境变量来禁用它。
解决方案是删除tensorflow 0.12.0rc0
并将其替换为默认Anaconda存储库中的tensorflow 0.10.0rc0
。
$ conda remove tensorflow
$ conda install tensorflow
$ conda list | grep tensorflow
tensorflow 0.10.0rc0 np111py35_0
----------
在版本10和12之间不推荐使用几个tensorflow函数。目前,版本12是OSX Anaconda Python的推荐张量流程包(从带有Anaconda pip的私有存储库安装)。任何需要在Mac和非gpu Linux上运行的脚本都应使用已弃用的版本10函数。 Mac用户需要抑制产生的警告。