1

This might be a possible duplicate, but i wasn't able to find a solution in the link here. I am new to raspberry PI I wish to use Pubnub to communicate with an android application and a Raspberry Pi. I have a raspberry Pi 3 model B with a freshly installed Raspbian OS.

I followed the initial steps from here.

Install Python:
pi@raspberrypi ~$ sudo apt-get install python-dev


Install pip:
pi@raspberrypi ~$ sudo apt-get install python-pip

install PubNub:
pi@raspberrypi ~$ sudo pip install pubnub

then I wrote the exact code and saved it as hello.py with my publish and subscription keys:

import sys
from pubnub import Pubnub

pubnub = Pubnub(publish_key='<your-pub-key>', subscribe_key='<your-sub-key>')

channel = 'hello-pi'

data = {
  'username': 'Your name',
  'message': 'Hello World from Pi!'
}

def callback(m):
  print(m)

pubnub.publish(channel, data, callback=callback, error=callback)

and i am getting this error:

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

Cannot find a solution and it is a very annoying error this early in my project. Please help.

thanks in advance.

Community
  • 1
  • 1
Vedant Aggrawal
  • 400
  • 4
  • 17
  • Did you install PubNub Python SDK v4 or v3? If v4 then you are importing wrong and the syntax of instantiating PubNub is different (uses camelCase not snake_case). https://www.pubnub.com/docs/python/pubnub-python-sdk-v4 – Craig Conover Dec 27 '16 at 17:29
  • Possible duplicate of [ImportError: cannot import name Pubnub](http://stackoverflow.com/questions/34354575/importerror-cannot-import-name-pubnub) – Paul Roub Feb 06 '17 at 23:38

2 Answers2

0

Use the following syntax (Case sensitive):

from pubnub.pubnub import PubNub
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

Use pip install 'pubnub>=3,<4'