vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.
https://blynk.io/
MIT License
286 stars 98 forks source link

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

Open abdul-rehman-2050 opened 1 year ago

abdul-rehman-2050 commented 1 year ago

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'?

ebolisa commented 1 year ago

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()
abdul-rehman-2050 commented 1 year ago

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.

ebolisa commented 1 year ago

the pip installed version.

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