nakaakist
nakaakist

Reputation: 358

facebook-python-ads-sdk - ImportError: cannot import name 'objects'

I installed facebookads according to the README.md (https://github.com/facebook/facebook-python-ads-sdk)

pip3 install facebookads

Then I tried to import facebookads in my python code according to the README.md.

from facebookads.api import FacebookAdsApi
from facebookads import objects

Then the following error appeared

Traceback (most recent call last):
  File "generate_facebook_campaigns.py", line 2, in <module>
    from facebookads import objects
ImportError: cannot import name 'objects'

I also tried git clone and ran the setup.py to install the module, but the result was the same.

How can I remove this error?

versions: python 3.5.2, pip 9.0.1, facebookads 2.9.1

Upvotes: 1

Views: 3264

Answers (1)

ikkuh
ikkuh

Reputation: 4613

It seems like the new versions 2.8.2 (19 days old) and 2.9.1 (8 days old) introduced this import error. Using version 2.8.1 doesn't give me this error:

$ pip install -I facebookads==2.8.1
...
$ python
>>> from facebookads import objects
>>>

They could have changed the library without changing the documentation. The file objects.py which existed in older versions seems to have been removed. The top of the file had the examplanation:

-This file is kept for backward compatibility.
-Please use objects in adobjects folder instead.

So in the new import would look as follows:

from facebookads.adobjects.<file> import <object>
# or
from facebook.adobjects import <file>
<file>.<object>

Looking at the old objects.py file shows us which file and object we need. For example for the old objects.Campaign object we use the following campaign.Campaign object:

from facebookads.adobjects import campaign
c = campaign.Campaign(...)

Upvotes: 5

Related Questions