Sean D
Sean D

Reputation: 4292

Pipenv can not load a module

I used pipenv to install facebookads, but it is having trouble resolving the AdUser module.

import facebookads
from facebookads.adobjects.adaccount import AdAccount 
from facebookads.adobjects.adsinsights import AdsInsights 
from facebookads.api import FacebookAdsApi
from facebookads import adobjects 
from facebookads.adobjects import AdUser

access_token = 'removed from code sample'
ad_account_id = 'removed from code sample'
app_secret = 'removed from code sample'
app_id = 'removed from code sample'
FacebookAdsApi.init(app_id, app_secret, access_token)

# Add after FacebookAdsApi.init
me = AdUser(fbid='me')
my_account = me.get_ad_accounts()[0]
print(my_account)

Pycharm shows an error: Unresolved reference: 'AdUser'

The console shows the following:

Traceback (most recent call last):
  File "F:/cp/python-scripts/tests-facebook.py", line 11, in <module>
    from facebookads.adobjects import AdUser
ImportError: cannot import name 'AdUser'

I've tried an uninstall and reinstall of facebookads SDK. It has not helped.

Another developer suggested a possible problem with the virtual environment.

Any insights on how to fix this would help, thank you.

Upvotes: 1

Views: 197

Answers (1)

cosinepenguin
cosinepenguin

Reputation: 1575

According to this GitHub thread, it seems AdUser has been renamed AdAccountUser. You could try the import statement

from facebookads.adobjects.adaccountuser import AdAccountUser

to fix your issue.

Hope it helps!

Upvotes: 3

Related Questions