Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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 从setup.py安装时,无法在Google Colab中导入Tensorflow 2.2.0rc2_Python_Tensorflow_Pip_Google Colaboratory_Importerror - Fatal编程技术网

Python 从setup.py安装时,无法在Google Colab中导入Tensorflow 2.2.0rc2

Python 从setup.py安装时,无法在Google Colab中导入Tensorflow 2.2.0rc2,python,tensorflow,pip,google-colaboratory,importerror,Python,Tensorflow,Pip,Google Colaboratory,Importerror,我正试图在Google Colab中导入Tensorflow的最新rc2版本(目前为2.2.0rc2),但从我的setup.py安装脚本安装时无法导入 当我使用手动安装Tensorflow时!pip安装tensorflow==2.2.0rc2从Colab单元开始,一切正常,我可以导入tensorflow 接下来是如何在Google Colab中安装依赖项: # Executes the cell in bash mode %%bash if [ ! -d "/content/deep-debl

我正试图在Google Colab中导入Tensorflow的最新rc2版本(目前为2.2.0rc2),但从我的setup.py安装脚本安装时无法导入

当我使用
手动安装Tensorflow时!pip安装tensorflow==2.2.0rc2
从Colab单元开始,一切正常,我可以导入tensorflow

接下来是如何在Google Colab中安装依赖项:

# Executes the cell in bash mode
%%bash

if [ ! -d "/content/deep-deblurring/" ]; 
    then 
        git clone https://github.com/ElPapi42/deep-deblurring;
        cd deep-deblurring/
    else 
        cd deep-deblurring/; 
        git pull; 
fi;

git checkout development
cd ..

pip uninstall -y tensorflow tensor2tensor tensorboard tensorboardcolab tensorflow-datasets tensorflow-estimator tensorflow-gan tensorflow-hub tensorflow-metadata tensorflow-privacy tensorflow-probability

pip install colab-env
pip install --upgrade grpcio

cd deep-deblurring/
python setup.py install
cd ..
下一个是我的setup.py文件:

#/usr/bin/python
#编码=utf-8
“”“安装并安装软件包和所有依赖项。”“”
从setuptools导入设置中,查找\u包
以open('requirements.txt')作为pro:
INSTALL\u REQUIRES=pro.read().split('\n')
设置(
作者='Whitman Bohorquez,Mo Rebaie',
作者惠特曼-2@hotmail.com',
name='deblurrer',
许可证,
description='Image Deburring using Deep Learning Architecture',
version='1.0.0',
url=“”,
packages=find_packages(),
include_package_data=True,
python_需要='>=3.6',
install\u requires=install\u requires,
分类器=[
“开发状态::Alpha”,
'编程语言::Python',
'编程语言::Python::3.6',
'目标受众::开发者',
],
)
下一个是存储库中的requirements.txt:

grpcio == 1.27.2
kaggle
numpy
tensorflow >= 2.2.0rc2
pandas
实际上,Google Colab附带了Tensorflow 2.2.0rc1,但我想要rc2。当我执行:

将tensorflow导入为tf
打印(tf.\U版本\U)
在执行setup.py安装脚本之前,导入工作正常。但是在使用setup.py完成安装后,会抛出错误
ImportError:没有名为'tensorflow'
的模块

我在执行
python setup.py安装之前和之后检查了tensorflow的安装,一切似乎都正常,安装前使用tensorflow 2.2.0rc1,安装后使用2.2.0rc2

正如我首先提到的,当我使用
手动安装tensorflow时!pip install tensorflow==2.2.0rc2
导入工作正常,所以问题一定是围绕着
setup.py
文件或需求之类的,但我没有看到它

希望你们的帮助

PD:这个项目设置在上周五的最后一周开始工作,但今天我尝试运行它,突然没有明显的原因而停止工作

PD2:这是我和你们分享的一个Colab笔记本,它设置了重现问题的代码

PD3:这是导入tensorflow时Google Colab中的完整错误回溯抛出:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/lib/python3.6/importlib/_bootstrap.py in _find_spec(name, path, target)

AttributeError: '_TensorflowImportHook' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
2 frames
<ipython-input-7-69e5d056d1fc> in <module>()
----> 1 import tensorflow as tf
      2 
      3 tf.__version__

/usr/local/lib/python3.6/dist-packages/google/colab/_import_hooks/_tensorflow.py in find_module(self, fullname, path)
     26     if fullname != 'tensorflow':
     27       return None
---> 28     self.module_info = imp.find_module(fullname.split('.')[-1], path)
     29     return self
     30 

/usr/lib/python3.6/imp.py in find_module(name, path)
    295         break  # Break out of outer loop when breaking out of inner loop.
    296     else:
--> 297         raise ImportError(_ERR_MSG.format(name), name=name)
    298 
    299     encoding = None

ImportError: No module named 'tensorflow'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
/usr/lib/python3.6/importlib//u bootstrap.py in\u find\u规范(名称、路径、目标)
AttributeError:“\u TensorflowImportHook”对象没有“find\u spec”属性
在处理上述异常期间,发生了另一个异常:
ImportError回溯(最近一次呼叫最后一次)
2帧
在()
---->1导入tensorflow作为tf
2.
3 tf.\u版本__
/查找模块中的usr/local/lib/python3.6/dist-packages/google/colab//\u import\u hooks//\u tensorflow.py(self、fullname、path)
26如果全名!='tensorflow':
27无返回
--->28 self.module_info=imp.find_模块(fullname.split('.')[-1],路径)
29回归自我
30
/find_模块中的usr/lib/python3.6/imp.py(名称、路径)
295断开#断开内环时,断开外环。
296其他:
-->297 raise ImportError(_ERR_MSG.format(name),name=name)
298
299编码=无
ImportError:没有名为“tensorflow”的模块
---------------------------------------------------------------------------
注意:如果由于缺少包而导致导入失败,则可以
手动安装依赖项使用!皮普或!恰当的。
要查看安装某些常见依赖项的示例,请单击
下面的“打开示例”按钮。
---------------------------------------------------------------------------

我找到了一个解决办法,但到目前为止,这并不是这个问题的解决方案,因此这不会被接受为解决方案,但会帮助有同样困难的人继续工作:

在安装自定义软件包之前手动安装您的需求,在我的例子中,这是
pip Install-r”/content/deep deblurring/requirements.txt“


目前这解决了导入问题,但这不是一个干净的解决方案,希望以后能有更好的解释

tensorflow没有问题,但是Colab的
\u TensorflowImportHook
缺少
find_spec
impl,因此如果将
tensorflow
安装为egg dir,则会出现问题。由于钩子除了发出将
tensorflow
更新为2.0和2.0的通知之外没有任何用处,因此一个简单的解决方法是从笔记本开始的某个地方清除它:

[1] import sys
    sys.meta_path[:] = [hook for hook in sys.meta_path if not h.__class__.__name__ == '_TensorflowImportHook']

[2] import tensorflow as tf
    print(tf.__version__)
[1] import sys
    sys.meta_path[:] = [hook for hook in sys.meta_path if not h.__class__.__name__ == '_TensorflowImportHook']

[2] import tensorflow as tf
    print(tf.__version__)