Python Facebook SDK: 'module' object has no attribute 'GraphAPI'

I am trying to run a basic example with the Facebook SDK for Python. I tried doing exactly what this tutorial does from the command line (with "pip install facebook" and "pip install facebook-sdk" successfully done first...):

import Facebook works okay, but graph = facebook.GraphAPI() gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'GraphAPI'

I'm not imtimately familiar with how modules work, but it looks like facebook somehow isn't recognized at all! Or something else is missing here. From the command line, I tried these things to investigate:

>>>dir(facebook)

Output:

['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__version__']

and...

>>>help(facebook)

Output:

Help on package facebook:

NAME
    facebook - TODO: Document your package.

FILE
    /Library/Python/2.7/site-packages/Facebook-0.0-py2.7.egg/facebook/__init__.py

PACKAGE CONTENTS


DATA
    __loader__ = <zipimporter object "/Library/Python/2.7/site-packages/Fa...
    __version__ = 'TODO: Enter a version'

VERSION
    TODO: Enter a version

(END) 

...But I'm still stuck. Do I need to "enter a version" to somehow get the thing to fully instantiate? Or could it be something else?

Answers


If you are using Ubuntu or Debian, Just execute the following commands to get this working

sudo pip uninstall facebook
sudo pip uninstall facebook-sdk
sudo pip install facebook-sdk

For other operating systems, just remove facebook and facebook-sdk packages and install only facebook-sdk.

And then execute that program, it will work. Looks like facebook module is a dummy module. What we actually need is facebook-sdk only.


I had the same problem when messing around with facebook-sdk for python the first time. It occured I named my python file "facebook.py", and made unconsiously a name clash.


I tried what @thefourtheye suggested but pip wasn't uninstalling everything. Instead, I just cleaned out the Facebook packages via

rm -rf /path/to/my/venv/lib/python2.7/site-packages/facebook* && rm -rf /path/to/my/venv/lib/python2.7/site-packages/Facebook* 

WARNING: check that you don't have any other packages that start with facebook before you go removing anything. In my case I had

facebook/    
Facebook-0.0-py2.7.egg-info/   
facebook.py    
facebook.pyc 
facebook_sdk-0.4.0-py2.7.egg-info/ 

I have the same problem. I renamed the file from facebook.py to first.py (You can choose your one name.)So, my conclusion is don't save file with a module name.


Need Your Help

Java abstract interface

java interface abstract

Consider an example (which compiles in java)

day of the week to day number (Monday = 1, Tuesday = 2)

php datetime date

Does php have a function to automatically convert dates to their day value, where Monday=1, Tuesday=2, etc. Something like this