evantkchong
evantkchong

Reputation: 2606

Google Colaboratory - AttributeError: module X has no attribute Y

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

Upvotes: 0

Views: 1610

Answers (1)

Scratch'N'Purr
Scratch'N'Purr

Reputation: 10399

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

Upvotes: 1

Related Questions