I am trying to follow the example on page 5 of the book: Mining the Social Web, from O'Reilly. I am coming across the following error:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'Twitter'
What might be going on?
Check the value of twitter.__file__ (after you've imported twitter). My guess is either you somehow got a broken version of twitter, or you've created a file called twitter.py in the same directory you're running from that's blocking the installed module from loading.
If twitter.__file__ looks good (points to where your installed modules should be instead of the local dir), try easy_install -U twitter to reinstall it.
Works for me. I installed twitter through easy_install, which installed the latest version (1.6.1). dir(twitter) also lists Twitter here.
You could remove the twitter package from site-packages and try reinstalling again.
Related
I am having trouble installing the cdstoolbox-remote on my Linux machine (tried both Ubuntu and Debian). I installed it using pip:
pip install cdstoolbox-remote
Which successfully installs the module, but I can't import the module in Python. Importing the module causes the following error:
>>> import cdstoolbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/an/miniconda2/envs/tools/lib/python3.7/site-packages/cdstoolbox/__init__.py",
line 8, in <module>
with open(__main__.__file__) as f:
AttributeError: module '__main__' has no attribute '__file__'
What can be done to get it working?
Do you really need cdstoolbox-remote? The standard API for downloading data from CDS would be cdsapi, which can be installed using
pip install cdsapi
or using conda (https://anaconda.org/conda-forge/cdsapi)
I also just tried installing cdstoolbox-remote and got the same problem. But as it is flagged as experimental I even consider it to be possible that the current version is not a stable version.
And cdsapi seems to work.
Actually, the CDSAPI can also be used to execute workflows as follows:
import cdsapi
c = cdsapi.Client()
with open("workflow.py") as f:
code = f.read()
r = c.workflow(code)
print(c.download(r))
For more, read this thread on the Copernicus services documentation.
Using Spotipy and am attempting to 'current_user_recently_played'
token = util.prompt_for_user_token(username, scope = scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
sp = spotipy.Spotify(auth = token)
saved = sp.current_user_saved_tracks()
print(saved)
recent = sp.current_user_recently_played()
print(recent)
sp.current_user_saved_tracks() runs just fine, sp.current_user_recently_played() apparently doesn't exist even though it is clearly in the documentation https://spotipy.readthedocs.io/en/latest/#more-examples.
Running - v2.4.4 - January 4, 2017
Thanks ahead of time.
Traceback (most recent call last):
File "C:\Users\Martin\Google Drive\Python\Spotify\try_req.py", line 19, in <module>
recent = sp.current_user_recently_played()
AttributeError: 'Spotify' object has no attribute 'current_user_recently_played'
You're going to have to get the code manually. The installation via pip is outdated.
Navigate to where you installed Spotipy (for me it was C:\Users\[myName]\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\spotipy), open client.py and replace the code with the newer code found here.
This is due to the outdated version on PyPi, as Mangohero1 already pointed out. The following method is probably easier than manually changing code.
You can install the latest code like this:
pip install git+https://github.com/plamere/spotipy.git --upgrade
(source)
After installing the facebook-sdk module here, and looking at other solutions here and elsewhere, I keep getting this error:
Traceback (most recent call last):
File "facebook.py", line 1, in <module>
import facebook
File "/home/facebook/facebook.py", line 3, in <module>
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
AttributeError: 'module' object has no attribute 'GraphAPI'
For this very simple python code to authenticate...
import facebook
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
print 'Workinnnn'
It says my module is installed and up to date, and I have installed both within (as suggested) a virtualenv and outside, and still get the error. I also definitely HAVE the module in usr/local/lib/python etc. dist packages... and it contains the class GraphAPI
Has anyone got a suggestion either:
1) What might be going wrong?
2) What to try to fix it? UNinstall something?
3) If there is another way other than pip to install the module... I don't normally use pip (but definitely have it installed and installed facebook-sdk from it) so if there's another way then I'd like to try...
Cheers :/
Solution = don't name your script the same as your module.
I'm an idiot, sigh...
I am trying to get Cherrypy to output json for a project and on my Mac adding the #cherrpy.tools.json_out() decorator is working a treat but on my Ubuntu 13.04 system I get this error.
Traceback (most recent call last):
File "cherrypy.py", line 1, in <module>
import cherrypy
File "/bla/cherrypy.py", line 4, in <module>
class Root(object):
File "/bla/cherrypy.py", line 6, in Root
#cherrypy.tools.json_out()
AttributeError: 'module' object has no attribute 'tools'
The code above is a direct copy from the bottom of this page.
http://tools.cherrypy.org/wiki/JSON
If i enter a python shell then run interactive help on the module I get a similar result.
help> cherrypy
problem in cherrypy - <type 'exceptions.AttributeError'>: 'module' object has no attribute 'tools'
I have tried searching but I can't find anyone else having the same issue? (Maybe I am missing the wood for the trees?)
I have tried reinstalling the package through apt and manually from the cherrypy source all against Python 2.7
Although I am developing on Mac and Ubuntu I will be deploying on an Ubuntu server so I would like to sort this out sooner rather than later.
Your help is much appreciated
Do you use python-cherrypy from ubuntu package? It's version is 2.3.0 which does not have cherrypy.tools modules.
Install newer version (sudo pip install -U cherrypy).
I installed oauth2:
$ pip install oauth2
But running the python-oauth2/example/client.py returns:
Traceback (most recent call last):
File "client.py", line 31, in <module>
import oauth.oauth as oauth
ImportError: No module named oauth.oauth
I tested pip freeze:
oauth2==1.5.211
Thanks in advance
As it turns out, the example directory in the oauth2 package should be ignored. It is broken code as far as the package is concerned.
See these issues for examples of other people discovering this:
https://github.com/simplegeo/python-oauth2/issues/33
https://github.com/simplegeo/python-oauth2/issues/12
https://github.com/simplegeo/python-oauth2/pull/64
The last one is a pull request that includes new examples to use instead.