I am relatively new to Colab & python, so I don't really know how to use it. I have git-cloned a GitHub repository onto my Colab notebook. There are some modules inside the GitHub folder that I have cloned that I need to import them into the notebook. For example, there is a utils and models module that I want to import. I ran the code:
from models import *
from utils import *
However, the Colab editor wrought the error ModuleNotFoundError: No module named 'models' and ModuleNotFoundError: No module named 'utils'. This led me to realize that I haven't imported the modules from the Git Hub clone in Colab Files into Colab. I couldn't find an answer on StackOverflow, w3schools, or the Colab official sites so I
wrought my question here. If any of you have a link to a guide or a solution, please help me. Thank you!
Yes, some of the Jupyter Notebook tricks worked. I used %cd pytorch_objectdetecttrack to get to the modules.
Not an expert in Colab, but for Python import only works for Python modules. So if there's a specific script you're trying to import, you will have to call it like import folder.someModule. The folder you're trying to access should go first, then the module name.
It's the same as saying ./folder/someModule.py.
tl:dr; You have to specify the path to the module if it's not in the current working directory.
Related
I have connected a Github repository to my Databricks workspace, and am trying to import a module that's in this repo into a notebook also within the repo. The structure is as such:
Repo_Name
Checks.py
Test.ipynb
The path to this repo is in my sys.path(), yet I still get ModuleNotFoundError: No module named 'Checks'. When I try to do import Checks. This link explains that you should be able to import any modules that are in the PATH. Does anyone know why it might still not be working?
I have tried doing the same and got a similar error even after following the procedure as given in the link provided in the question.
I have the following python files in my GIT repo (3 files with .py extension).
Now when I add the path /Workspace/Repos/<username>/repro0812 to sys.path and try to import the sample module from this repo, it throws the same error.
This is because, for some reason, this file is not being rendered as a python file. When I open the repo, you can actually see the difference.
There was no problem while I import the other 2 python modules check and sample2. The following is an image for refernce.
Check and make sure that the file is being considered as a .py file after adding your repo.
I met troubles in importing my own modules. As you can see it said no module named guvBB, but I actually have guvBB.py. What is the problem? Thank you
you have added the path on your system to the path on colab.
google doesnt have access to c://.......
go to table of content, find the folder,right click on it and put that path in your code sys.path.append(newpath).
I'm trying to use the Freesound API in a Google Colaboratory notebook (running Python 3) to generate a database of sounds for which to do machine learning with. However I have been unable to use the definitions in a module I imported.
I've looked at other similar questions but they did not seem to address my issue (most were cases of trying to import a module in the standard python library and instead importing a .py file of the same name) and I apologize if this particular issue has been covered somewhere else.
The boilerplate code is as follows:
#clone relevant Git repo
!git clone https://github.com/MoltenMuffins/freesound-python
!ls
#Import packages
import os
import sys
import requests
#Open module file and import module
open('freesound.py','wb')
import freesound
There is some code after that but it is not relevant to the issue. Running this last code block is what gives me the Attribute Error despite FreesoundClient being defined in the freesound.py file cloned from the repo:
freesound_client = freesound.FreesoundClient()
I would greatly appreciate an explanation regarding this issue!
Here's a link to the colabs notebook if you'd like to take a look
I would follow the repo's instructions of using their setup.py to do the installation:
After cloning the git repo, you want to change your working directory to the freesound-python directory and run setup.py
import os
os.chdir('/content/freesound-python')
!python setup.py install
# now import the module
import freesound
I am currently working on a project on Machine Learning on Google Colab which uses Tensorflow API. I created a folder and uploaded it on google drive to run on google Colab.
I successfully mounted the google drive and can run the script,
But when I try importing another module from the script present in the same folder, it throws an error
from . import inference
ImportError: cannot import name 'inference'
I tried finding out a solution for this but found results stating how to import a module directly to the colab notebook.
Please tell me what I am missing here.
Edit:
The folder structure is
-nmt
-nmt.py
-train.py
-inference.py
-utils
-evaluation.py
and so on.
And I am running the python file from the nmt folder. I am getting relative import errors.
Try this. First, upload the .py file and then save it locally. Then you may use it as you like it.
from google.colab import files
src = list(files.upload().values())[0]
open('library_you_want_to_use.py','wb').write(src)
import library_you_want_to_use
I am trying to run PCA on my dataset. I came across a tutorial by Ritchie Ng: https://www.ritchieng.com/machine-learning-project-customer-segments/
and i am trying to recreate it on my dataset. However, the blog uses a package called "renders" which i am unable to find in Anaconda. How and where do i get and enable this package from? I have searched for this package in Anaconda navigator and google but i cant seem to find it.
here's the link to 'renders', as provided in the tutorial:
https://github.com/ritchieng/machine-learning-nanodegree/tree/master/unsupervised_learning/customer_segments
Make sure you have module file in directory.
Module: A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py
appended.
Read more: Python Tutorial - Modules