I had import and mount the data in ggdrive by this code
import pandas as pd
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
And then i call back a def in this file
from data.generator import DataGenerator
So i had a problem with this module name,it isn't name of a module ,it's a name of a file in direct folder. Hope someone can solve this problem for me
You have to run the python script from the right folder. So before running the python script add a line like:
%cd "/content/gdrive/MyDrive/Machine Learning/005 Handwriting Recognition/handwritten-text-recognition/src"
Related
I would like to import a .ipynb file with importnb. I tried to use the classic:
from importnb import Notebook
with Notebook:
import custom_probability
I get Import <module> could not be resolved
I'm using Anaconda but I'm not sure if it could be related to a path or environment problem.
I am trying to run my project using the gpus but I can't get it to work.
I have ran the following commands:
from google.colab import drive
drive.mount('/content/gdrive')
%cd gdrive/MyDrive/project_folder
import sys
sys.path.append('/content/gdrive/MyDrive/project_folder')
I then try to run my main script from project_folder by using
! python property_prediction/predict.py
In the first line of predict.py I import a module from the folder 'project_folder' but that gives this error in colab:
File "property_prediction/predict.py", line 17, in <module>
from GP.kernels import Shortest_Path
ModuleNotFoundError: No module named 'GP
Why is it not finding the folder GP which contains my kernels script?
Try to replace your running command with:
!python -m property_prediction.predict
Or better:
from property_prediction.predict import predict # or whatever your main function is called
predict()
NB: This is of course assuming that you have a module named GP in the folder project_folder
If none of this work, you might be interested in reading this or other articles about imports with python (this is most likely not a problem of google collab)
I created a working folder: C:\Users\robin\bayesian-optim
Inside there are module1_test.py and work.py
I have some functions in module1_test.py that I want to use in work.py, but using import module1_test as mmm in the shell gives the following error :
ImportError: No module named 'dossier_module'
It is the first thing that I do not understand. To go further,
I tried this :
import sys
sys.path.insert(0,'C:/Users/robin/bayesian-optim')
Then it worked, but my real goal is to clone some git codes in this folder and to call them instead of my example module1_test.py. When I do so, cloning "pymoo" in C:\Users\robin\bayesian-optim, I have the same problem :
File "C:/Users/robin/bayesian-optim\pymoo\pymoo\__init__.py", line 1, in <module>
from pymoo.version import __version__
ImportError: No module named 'pymoo.version'
All the .py folders inside of the cloned repo are not foundable, and it would mean that I would have to add at the beginning of every code "import sys, sys.path.insert(0, path/to/this/folder)". Can somebody help me ?
I am working on a python program in colab.
I need to import another file here. The file is saved by the name "base_positioner.ipynb" in google drive....
I have gone through multiple resources to see how to do this import and I have done the following:
from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive/My Drive
On running !ls , I see 'base_positioner.ipynb' in the list but
still running : import base_positioner throws the module not found error
I had also tried the following but with no success in importing the desired file:
sys.path.append('/content/gdrive/My Drive/Colab Notebooks')
What else should I try??
This could happen if you haven't mounted your Drive on Colab to the backend properly and also possibly if your file layout in Drive is distinct from the file layout in Colab. Are you running the import command without running the following code?
from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive/My Drive
If you are doing that then this won't work, as this is a pre-requisite for the mounting to take place (i.e. not running the cells sequentially). You can also try restarting Google Colab and this often fixes any strange errors.
Update:
As you mentioned, the import error likely happens due to its configuration in the main file (i.e. it requires the file to be in the .py format to be imported just as import base_positioner).
To import .ipynb extension file you will need to follow the following process:
If you want to import A.ipynb in B.ipynb write
import import_ipynb
import A
The import_ipynb module can be installed via pip or any other relevant ways.
pip install import_ipynb
I've downloaded pymumble from https://github.com/Robert904/pymumble and saved it to my working directory. I import it with:
from pymumble import pymumble
However, I receive:
ImportError: No module named pymumble
I'm looking at similar code that does this successfully. What am I doing wrong when trying to import this?
As I can see there is no file called pymumble in given repository, if you are looking for this there is a file called mumble.py, try importing
from mumble import mumble
this will work.