0

i have problem with pubhub module in python 2.7.6.

I've installed by sudo pip install pubnub

Output:

>>> import pubnub
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pubnub.py", line 3, in <module>
    from pubnub import Pubnub
ImportError: cannot import name Pubnub

>>> from pubnub import Pubnub
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pubnub.py", line 3, in <module>
    from pubnub import Pubnub
ImportError: cannot import name Pubnub

I reinstalled requests, python-dev and pubnub. Nothing helped

In help('modules') there is module pubnub

4 Answers4

2

for version 4 of pubnub the instantiation has changed,

from pubnub import pubnub
pnconf = pubnub.PNConfiguration()
pnconf.subscribe_key = 'demo'
pnconf.publish_key = 'demo'

pubnub = pubnub.PubNub(pnconf)

for more information read their documentation v4 upgrading for pubnub

Chandan Purohit
  • 2,283
  • 1
  • 17
  • 16
1

You have a file in your project called pubnub.py, which the importer is finding before your installation of the pubnub module, I think. Rename your file to something else, and everything should work.

Adam Barnes
  • 2,922
  • 21
  • 27
1

I renamed file, removed python3(it was installed still :D), and removed every *.pyc files and it is working for now. Thanks

0

I experienced the same problem on my Raspberry Pi 3. It ended up being a very silly issue! I had a file called pubnub.py which is why when I ran my script when it was located in the folder "Desktop" it didn't work. However, after I brought it up to its parent directory "pi" it imported pubnub without an issue!

castillejoale
  • 519
  • 4
  • 13