ImportError cannot import name Pubnub

0 votes

I am trying to control an LED on my Raspberry Pi with the Pubnub platform. 

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,270 points
1,386 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,280 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,160 points
744 views
0 votes
1 answer

Arduino to pubnub cloud using esp8266

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

answered Oct 27, 2018 in IoT (Internet of Things) by Siddhant
• 210 points
1,025 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 28, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
699 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,620 points
613 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,391 views
0 votes
1 answer
0 votes
1 answer

Choosing Domain Name for IoT Device

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

answered Sep 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
2,878 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP