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
156 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
28 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
113 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,100 points
22 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
• 7,480 points
19 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 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
60 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.