Reputation: 524
Im trying to import the latest rc2 version of Tensorflow (2.2.0rc2 at this date) in Google Colab, but cant do it when installed from my setup.py install script.
When i install Tensorflow manually using !pip install tensorflow==2.2.0rc2
from a Colab cell, everything is ok and im able to import Tensorflow.
The next is how i have my dependencies installation setup in 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 ..
The next is my setup.py file:
#!/usr/bin/python
# coding=utf-8
"""Setup and install the package and all the dependencies."""
from setuptools import setup, find_packages
with open('requirements.txt') as pro:
INSTALL_REQUIRES = pro.read().split('\n')
setup(
author='Whitman Bohorquez, Mo Rebaie',
author_email='[email protected]',
name='deblurrer',
license='MIT',
description='Image Deblurring using Deep Learning Architecture',
version='1.0.0',
url='',
packages=find_packages(),
include_package_data=True,
python_requires='>=3.6',
install_requires=INSTALL_REQUIRES,
classifiers=[
'Development Status :: Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Intended Audience :: Developers',
],
)
The next is the requirements.txt on the repository:
grpcio == 1.27.2
kaggle
numpy
tensorflow >= 2.2.0rc2
pandas
Actually, Google Colab ships with Tensorflow 2.2.0rc1, but i want the rc2. when i execute:
import tensorflow as tf
print(tf.__version__)
before executing the setup.py installation script, the import works normally. But after the installation using setup.py is done, the error ImportError: No module named 'tensorflow'
is throw.
I checked the tensorflow installation before and after the python setup.py install
execution and everything seems to be ok, with tensorflow 2.2.0rc1 before installation and 2.2.0rc2 after installation.
as i mention first, when iinstall tensorflow manually using !pip install tensorflow==2.2.0rc2
the import works as espected, so the problem must be around setup.py
file or requirements, something like that, but im not seeing it.
Hope your help guys!
PD: this project setup was working the last week on friday, but today i try to run it, and suddenly stops working with no apparent reason.
PD2: https://colab.research.google.com/drive/1Qv8h4ceEtDTq5lvt1uKJG8dk53_bUqBZ this is a Colab Notebook i share with you, this setups the code for reproduce the issue.
PD3: this is the full error traceback throw in Google Colab while importing tensorflow:
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
Upvotes: 0
Views: 1203
Reputation: 66171
There's nothing wrong with tensorflow
, but rather with Colab's _TensorflowImportHook
missing find_spec
impl so it will raise if tensorflow
is installed as egg dir. Since the hook doesn't do anything useful besides issuing a notification to update tensorflow
to 2.0 and is scheduled for removal anyway, an easy fix would be purging it from sys.meta_path
somewhere at the start of the notebook:
[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__)
Upvotes: 1
Reputation: 524
I found a work around, but this is not the solution to this problem by far, so this will not be accepted as solution, but will help people in same trouble to keep going with their work:
Install your requirements manually before installing your custom package, in my case, this is pip install -r "/content/deep-deblurring/requirements.txt"
:
# 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
pip install -r "/content/deep-deblurring/requirements.txt"
cd deep-deblurring/
python setup.py install
cd ..
Currently this fix the import issue, but this is not a clean solution, lets hope a better explanation later!
Upvotes: 0