8

I have installed facebook-sdk using below mentioned command:

pip install facebook-sdk

But while importing it, I am facing an issue:

import facebook
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python33\lib\site-packages\facebook.py", line 222
    except urllib2.HTTPError, e:
                            ^
SyntaxError: invalid syntax

How can I fix this?

1
  • Try to pip3 install --upgrade pip Then do pip3 install facebook-sdk make sure to update first & make sure to use pip3 if you have both versions 2 & 3 as I do on my Mac OSX Commented Feb 2, 2019 at 3:57

3 Answers 3

7

That is an old syntax for catching exceptions. It should have been replaced with the keyword as since Python 2.6, and it is probably not supported at all on Python 3.

Try to find another library that does support Python 3, or consider downgrading to Python 2.6 (which should really be a last-resort option).

You can review all details on PEP 3110.

Sign up to request clarification or add additional context in comments.

Comments

7

Check out This version: https://github.com/pythonforfacebook/facebook-sdk/tree/b9b0de30402bb99387f35630446b5446a288d14b

Download it and install with:

python setup.py install.

It works for me:

$ pip freeze --local

facebook-sdk==1.0.0a0

:)

1 Comment

You could also use pip install with the zip archive address: pip install https://github.com/mobolic/facebook-sdk/archive/b9b0de30402bb99387f35630446b5446a288d14b.zip
4

According to the documentation Facebook-SDK will not work with Python3.4 yet if you are using this version: https://facebook-sdk.readthedocs.org/en/latest/install.html

1 Comment

Update: The SDK currently supports Python 2.7 and Python 3.4-3.7. The requests package is required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.