blynk-library-python icon indicating copy to clipboard operation
blynk-library-python copied to clipboard

AttributeError: module 'os' has no attribute 'uname'. Did you mean: 'name'?

Open abdul-rehman-2050 opened this issue 1 year ago • 3 comments

I am trying to run the example code on Windows 10 and when simple import cause this error

import BlynkLib Traceback (most recent call last): File "<pyshell#8>", line 1, in import BlynkLib File "C:\Program Files\Python311\Lib\site-packages\BlynkLib.py", line 49, in /___/ for Python v""" + _VERSION + " (" + os.uname()[0] + ")\n") AttributeError: module 'os' has no attribute 'uname'. Did you mean: 'name'?

abdul-rehman-2050 avatar Jun 15 '23 14:06 abdul-rehman-2050

I am trying to run the example code on Windows 10 and when simple import cause this error

AttributeError: module 'os' has no attribute 'uname'. Did you mean: 'name'?

You're using the wrong library!

print("""
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \\/  '_/
 /____/_/\\_, /_//_/_/\\_\\
        /___/ for Python v""" + __version__ + " (" + sys.platform + ")\n")

test code:

from __future__ import print_function

import BlynkLib
import errno
import socket
import time
from BlynkTimer import BlynkTimer

BLYNK_AUTH = '-------'
blynk = BlynkLib.Blynk(BLYNK_AUTH)
timer = BlynkTimer()
cnt = 0

def update_virtual_led():
  global cnt
  if(cnt%2 == 0): #check for even number
    blynk.virtual_write(10, 0)
    time.sleep(.1)
  else:
    blynk.virtual_write(10, 255)
    time.sleep(.1)
  cnt += 1


def uptime():
  blynk.virtual_write(0, round(time.time() / 1000, 2))


@blynk.on("connected")
def blynk_connected(ping):
    print('Blynk ready. Ping:', ping, 'ms')
    blynk.sync_virtual()


@blynk.on("disconnected")
def blynk_disconnected():
    print('Blynk disconnected')


timer.set_interval(1, update_virtual_led) #update virtual leds 1 secs
timer.set_interval(1, uptime)


if __name__ == "__main__":
    #init() #run once
  while True:
    try:
      blynk.run()
      timer.run()
    except socket.error as e:
      if e.errno != errno.EPIPE:
        print("msg from blynkmain @ " + str(dt.now()))
        raise
        #blynk.connect()

ebolisa avatar Jun 15 '23 16:06 ebolisa

I installed it with the pip command mentioned in the readme and the os still cause the error. But then I copied the BlynkLib.py file and placed it in the same folder of the testing code and it works. I am new to this and not sure why and how it works with the source file rather then the pip installed version.

abdul-rehman-2050 avatar Jun 16 '23 12:06 abdul-rehman-2050

the pip installed version.

What that did is pulling the lib from a different git. “os.uname” was the clue 😉

ebolisa avatar Jun 16 '23 13:06 ebolisa