ImportError: cannot import name Pubnub

0 votes

I am trying to control an LED on my Raspberry Pi with the Pubnub platform. I just started and I tried this tutorial:

https://www.pubnub.com/blog/2015-05-27-internet-of-things-101-getting-started-w-raspberry-pi/

However, when I want to execute a Python file that imports the Pubnub library with the following line:

from pubnub import Pubnub

I get this error message:

ImportError: cannot import name Pubnub

I did everything exactly as told in the tutorial. I even copied the .py classes from their Github repository.

This is my class:

import RPi.GPIO as GPIO
import time
import sys
from pubnub import Pubnub

GPIO.setmode (GPIO.BCM)

LED_PIN = 17

GPIO.setup(LED_PIN,GPIO.OUT)

pubnub = Pubnub(publish_key='xxxx', subscribe_key='xxxx')

channel = 'disco'

def _callback(m, channel):
        print(m)
        if m['led'] == 1:
                for i in range(6):
                    GPIO.output(LED_PIN,True)
                    time.sleep(0.5)
                    GPIO.output(LED_PIN,False)
                    time.sleep(0.5)
                    print('blink')

def _error(m):
        print(m)

pubnub.subscribe(channels=channel, callback=_callback, error=_error)
Jul 27, 2018 in IoT (Internet of Things) by Matt
• 2,260 points
273 views

1 answer to this question.

0 votes

If you're running into this since early November 2016; the pubnub API has changed in version 4.0.

from pubnub import Pubnub

does not work. It's now (to my best knowledge):

from pubnub.pubnub import PubNub
answered Jul 27, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

AWS IOT Button Wifi network name

You can read about the complete setup ...READ MORE

answered Oct 12, 2018 in IoT (Internet of Things) by Annie97
• 2,190 points
45 views
0 votes
1 answer

Arduino to pubnub cloud using esp8266

With the ESP8266, it always better to ...READ MORE

answered Oct 26, 2018 in IoT (Internet of Things) by Siddhant
• 210 points
176 views
0 votes
1 answer

RPi2 PsSession: Warning - “Command 'iotstartup' cannot be found”

iotstartup such as setcomputername are executables. So, use ...READ MORE

answered Nov 27, 2018 in IoT (Internet of Things) by DataKing99
• 8,130 points
28 views
0 votes
1 answer

Pico PRO Market Kit : Cannot flash IoT image

Looked int flash-all.bat script which says: The fastboot executable must ...READ MORE

answered Dec 5, 2018 in IoT (Internet of Things) by Upasana
• 8,530 points
33 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 222 views
0 votes
1 answer

Choosing Domain Name for IoT Device

Yes, I would avoid revealing an 'internal' ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
131 views