Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 运行基本tensorflow示例时出错_Python_Ubuntu_Tensorflow - Fatal编程技术网

Python 运行基本tensorflow示例时出错

Python 运行基本tensorflow示例时出错,python,ubuntu,tensorflow,Python,Ubuntu,Tensorflow,我刚刚在ubuntu上重新安装了最新的tensorflow: $ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl [sudo] password for ubuntu: The directory '/home/ubuntu/.cache/pip/http' or its parent direct

我刚刚在ubuntu上重新安装了最新的tensorflow:

$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
[sudo] password for ubuntu: 
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
  Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 32kB/s 
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: protobuf==3.0.0b2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: tensorflow
  Found existing installation: tensorflow 0.7.1
    Uninstalling tensorflow-0.7.1:
      Successfully uninstalled tensorflow-0.7.1
Successfully installed tensorflow-0.7.1
当按照指示进行测试时,无法导入名称pywrap_tensorflow失败:


是否需要对我的python或ubuntu/bash环境进行其他更改?

从堆栈跟踪/git/tensorflow/tensorflow/…中的路径来看,您的python路径可能是从源目录加载tensorflow库,而不是从您安装的版本加载tensorflow库。因此,无法找到已编译的pywrap_tensorflow库,该库安装在不同的目录中

一个常见的解决方案是在启动python或ipython之前将cd从/git/tensorflow目录中取出。

我解决了这个问题。 请尝试执行以下命令:


pip安装-升级pip

我从源GitHub编译、安装了TensorFlow:在Python2.7虚拟环境venv中。它工作得很好,但正如其他人所提到的,我需要将用户mrry at to cd从我编译TensorFlow的分区中移出到另一个分区,以便能够将TensorFlow导入Python。否则,我会出现各种错误,这取决于我所在的源分区目录。澄清:

         source: /mnt/Vancouver/apps/tensorflow
can't import tf: Python launched in any of /mnt/...
  can import tf: Python launched in /home/victoria/...
我后来只是按照这里的指示做的

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
一切正常,很好

作为参考,我正在进行手术

Arch Linux[4.6.3-1-Arch]x86_64 英特尔i7-4790 xfce 4.12桌面环境 安装步骤:

根据您的首选项修改路径、venv名称

创建tf环境:

cd /home/victoria/anaconda3/envs

conda create -n tf-env python=2.7 anaconda
注意:附加“anaconda”元包将安装所有anaconda包NumPy

源激活该venv tf env

source activate tf-env
注意:作为别名添加到~/.bashrc:

alias tf='echo "  [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env'
将TensorFlow安装在tf环境通风孔中:

(tf-env)$ conda install -c conda-forge tensorflow
这避免了使用pip,包括*.whl安装脚本,这是一种安装TensorFlow的替代方法,如下所述:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md).
工作

(tf-env)[victoria@victoria ~]$ P

  [P: python]
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul  2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org

>>> import tensorflow
>>> print tensorflow.__version__
0.9.0
>>> [Ctrl-D]

(tf-env)[victoria@victoria ~]$

然后,您可以在tf环境中使用TensorFlow;e、 例如,在这个tf环境中启动的Jupyter笔记本电脑中。

下面的命令帮助了我

 pip install tensorflow --upgrade --force-reinstall
在我的python-m venv环境中,它似乎是通过以下方式修复的:

pip uninstall tensorflow
将requirements.txt改为tensorflow==1.5.0,而不是tensorflow==1.8.0


如果您使用2011年之前生产的CPU,则将tensorflow版本从1.8.0降级到1.5.0或1.2.0,并尝试导入它为我工作的模块。

通过以下命令安装解决了问题:

pip安装-升级


下面是下载的步骤

我发现TensorFlow 1.12.0只适用于Python版本3.5.2。我有Python3.7,但那不起作用。所以,我不得不降级Python,然后我可以安装TensorFlow,它可以正常工作

将python版本从3.7降级到3.6

conda install python=3.6.8

我用的是tensorflow 1.13.1。只是重新安装tensorflow对我来说很有效

我也有这个问题,并且已经研究了很长时间。在Python3+上似乎没有这样的问题。在py2.7上——问题实际上在google.protobuf上

解决方案1: 解决方案2: 在google文件夹中创建一个_uinit__uu.py

希望它能起作用。

Tensorflow 2.0兼容答案:mrry的解决方案和neustart47针对Tensorflow版本>=2.0的工作

回答1:在启动python或ipython之前,请将cd从/git/tensorflow目录中取出

回答2:pip安装tensorflow-升级-强制重新安装或
!pip安装tensorflow==2.0-强制重新安装

对延迟表示歉意。看来你是对的:我刚从我的home dir开始使用ipython,它可以很好地导入tensorflow,因为它不适合我。我可以看到C:\Python35\Lib\site packages\tensorflow\python\u pywrap\u tensorflow\u internal.pyd,但得到的错误是:从tensorflow.python.pywrap\u tensorflow\u internal import*导入错误:DLL加载失败:找不到指定的模块。我仍然对这个解决方案感到困惑。它可以工作,但是python包不应该依赖于当前工作目录来加载依赖项。因此,我似乎无法将IDE pydev配置为使用tensorflow gpu。tensorflow cpu工作正常。我错过什么了吗?
pip install -r requirements.txt
conda install python=3.6.8
pip uninstall protobuf
pip uninstall google
pip install google
pip install protobuf
pip install google-cloud
cd /path/to/your/env/lib/python2.7/site-packages/google
touch __init__.py