我刚刚在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 :
$ ipython
/git/tensorflow/tensorflow/__init__.py in <module>()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
/git/tensorflow/tensorflow/python/__init__.py in <module>()
43 _default_dlopen_flags = sys.getdlopenflags()
44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
46 sys.setdlopenflags(_default_dlopen_flags)
47
ImportError: cannot import name pywrap_tensorflow
我的python或ubuntu / bash环境是否需要进行其他更改?
答案 0 :(得分:171)
从堆栈跟踪(/git/tensorflow/tensorflow/…
)中的路径看,您的Python路径可能正在从源目录加载tensorflow库,而不是您已安装的版本。因此,它无法找到(已编译)pywrap_tensorflow
库,该库安装在不同的目录中。
在开始cd
或/git/tensorflow
之前,常见的解决方案是python
目录之外的ipython
。
答案 1 :(得分:8)
下面的命令帮助了我。
pip install tensorflow --upgrade --force-reinstall
答案 2 :(得分:4)
我在Python 2.7虚拟环境(venv)中编译并从源代码(GitHub:https://github.com/tensorflow/tensorflow)安装了TensorFlow。它工作正常,但我需要(正如其他人提到的,例如Error running basic tensorflow example处的用户“mrry”)从我编译TensorFlow的分区cd到另一个分区,以便能够导入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
一切正常,很好。
作为参考,我正在
进行操作安装步骤:
根据您的偏好修改路径,venv名称。
创建tf-env:
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'
在tf-env venv中安装TensorFlow:
(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-env中使用TensorFlow;例如,在这个(tf-env)venv。中推出的Jupyter笔记本中。
答案 3 :(得分:1)
在我的python -m venv environment
中,它似乎是通过以下方式解决的:
pip uninstall tensorflow
将requirements.txt
改为tensorflow==1.5.0
,而不是tensorflow==1.8.0
。
pip install -r requirements.txt
答案 4 :(得分:1)
如果您使用2011年之前制造的CPU,然后将tensorflow版本从1.8.0降级到1.5.0或1.2.0,然后尝试导入对我有用的模块。
答案 5 :(得分:1)
Tensorflow 2.0兼容答案:mrry的解决方案和neustart47在Tensorflow版本> = 2.0上的工作。
答案1:在启动python或ipython之前,从 cd
目录中退出 /git/tensorflow
。
答案2: pip install tensorflow --upgrade --force-reinstall
或
!pip install tensorflow==2.0 --force-reinstall
答案 6 :(得分:0)
答案 7 :(得分:0)
我发现TensorFlow 1.12.0仅适用于Python版本3.5.2。我有Python 3.7,但没有用。因此,我必须降级Python,然后才能安装TensorFlow。
要将python版本从3.7降级到3.6
Xcode
答案 8 :(得分:0)
我正在使用tensorflow 1.13.1。只是重新安装tensorflow对我有用。
答案 9 :(得分:0)
我也有这个问题,并且已经研究了很长时间。似乎在python 3+上没有这样的问题。在py2.7上-问题实际上出在google.protobuf
with open("pagesource.txt", 'r') as file:
results = []
for line in file:
if 'roster-timeblock-home' in line:
print(line)
results.append(line) # Here if you use a simple variable, it will be overwritten in case of every new match.
with open("shifts.txt", 'w') as file:
file.write("\n".join(results))
在“ google”文件夹中创建一个pip uninstall protobuf
pip uninstall google
pip install google
pip install protobuf
pip install google-cloud
。
__init__.py
希望它能工作。
答案 10 :(得分:-6)
我解决了这个问题。 请尝试以下命令:
pip install --upgrade pip