Error while importing facebook module in Python

别等时光非礼了梦想. 提交于 2021-02-07 12:32:07

问题


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:


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.




回答2:


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

:)




回答3:


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



来源:https://stackoverflow.com/questions/22990928/error-while-importing-facebook-module-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!