Importing a python module into colab - ModuleNotFoundError - python

Im trying to import a colab file as a module with a function (def) to be used in this new colab file.
from google.colab import drive
drive.mount('/content/drive')
I tried all of these calls:
#!cp "drive/My Drive/Colab Notebooks/Aulas_Cursos/test_module" .
!cp '/content/drive/My Drive/Colab Notebooks/Aulas_Cursos/test_module' .
#import sys
#sys.path.insert(0,'/content/drive/My Drive/ColabNotebooks/Aulas_Cursos')
#sys.path.append('/content/gdrive/My Drive')
import test_module
But i got the same error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-42-1a0689a1a9af> in <module>()
----> 1 import test_module
ModuleNotFoundError: No module named 'test_module'
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------

Related

ImportError: cannot import name 'preprocess_input' from 'tensorflow.keras.preprocessing'

I'm working on google colab , and I want to import preprocess_input from tensorflow.keras.preprocessing but this error keeps occurring , while whatever I import from tensorflow work fine except this .
well i'm using tensorflow = 2.8.0
my code :
from tensorflow.keras.preprocessing import preprocess_input
the error :
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-2569fd104ea5> in <module>()
----> 1 from tensorflow.keras.preprocessing import preprocess_input
ImportError: cannot import name 'preprocess_input' from 'tensorflow.keras.preprocessing' (/usr/local/lib/python3.7/dist-packages/keras/api/_v2/keras/preprocessing/__init__.py)
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
what should I install or change to fix this error , i just want to use preprocess_input for model predicting purposes that's all , any suggestions please !

ImportError: cannot import name 'RasaNLUConfig' from 'rasa_nlu.config' in Google Colaboratory

I'm trying to make a NLU model. When I run
from rasa_nlu.config import RasaNLUConfig
I get an error:
ImportError Traceback (most recent call last)
<ipython-input-1-c2bca1b53b6f> in <module>
----> 1 from rasa_nlu.config import RasaNLUConfig
2 from rasa_nlu.model import Trainer
ImportError: cannot import name 'RasaNLUConfig' from 'rasa_nlu.config' (/usr/local/lib/python3.7/dist-packages/rasa_nlu/config.py)
I thought, "Meh,not a big issue, Colaboratory just hasn't got Rasa installed by default, I'll just install it".
So when I installed it with !pip install rasa_nlu, it did everything, and then it told me to restart the runtime and gave me a button to do that. I did that, then I ran from rasa_nlu.config import RasaNLUConfig and I still get the same error:
ImportError: cannot import name 'RasaNLUConfig' from 'rasa_nlu.config'
I am not familiar with !apt so I don't know how I'm supposed to install Rasa with that. Will the problem be solved with that? Or is it something else?
Looks like I was using a newer version of rasa_nlu (0.15.1). The tutorial I was following used 0.11.3. In 0.11.3, RasaNLUConfig was located at from rasa_nlu.config. But in 0.15.1, it was someplace else.
So... that's solved!

how do you import my own module on colab?

I developp on colab and i save my code to create my own module qrl.py on drive but in my qrl.y i use !pip install deplacy and import numpy.
if i try to import the module i have the error following
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-58-62dca1f58066> in <module>()
----> 1 import grl
ModuleNotFoundError: No module named 'grl'
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
Trying copying the file to /content/ and build your module there. It's not able to access qrl.py (or grl) file.

Importing library Utils

I am working on image classification and using Google colab for this purpose.
But when I want to import the following modules, it throws an error.
from utils import show_test_cases, test_case_checker, perform_computation
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-ff42356cc1b5> in <module>()
----> 1 from utils import show_test_cases, test_case_checker, perform_computation
ImportError: cannot import name 'show_test_cases'
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------

Submodule import not working on Google Colab

I have a package called boo which I install on google colab from a github repository. The installation process looks fine and results in success message Successfully installed boo-0.1. However import boo fails on first internal import.
I replicated the same installation steps in a local virtual environment and package worked, but not on collab.
Here are my steps and error trace:
!rm -rf sandbox
!git clone https://github.com/ru-corporate/sandbox.git
!pip install -r sandbox/requirements.txt
!pip install sandbox/.
Alternatively, I tried
!pip install git+https://github.com/ru-corporate/sandbox.git#master
The error trace is:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-fc0b1d036b35> in <module>()
----> 1 import boo
/usr/local/lib/python3.6/dist-packages/boo/__init__.py in <module>()
----> 1 from boo.boo import download, build, read_dataframe, files
2 from boo.views.whatis import whatis
/usr/local/lib/python3.6/dist-packages/boo/boo.py in <module>()
3 from tqdm import tqdm
4
----> 5 from boo.file.download import curl
Basically, from root __init__.py the import goes to root boo.py and stumbles upon finding boo/file/download.py.
How do I make this package work on collab?
I could fix the subpackage behavior by editing setup.py as suggested here:
# ...
packages=setuptools.find_packages()
# ...
Somehow Colab is more restrictive on this parameter than local installation.

Categories

Resources