Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...):

enter image description here

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?

like image 540
norman Avatar asked Nov 10 '13 18:11

norman


4 Answers

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.

like image 52
user3878801 Avatar answered Nov 17 '22 21:11

user3878801


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.

like image 43
thefourtheye Avatar answered Nov 17 '22 23:11

thefourtheye


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/ 
like image 1
Meistro Avatar answered Nov 17 '22 23:11

Meistro


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.

like image 1
Kartik Prajapati Avatar answered Nov 17 '22 23:11

Kartik Prajapati