NiklasRosenstein / myo-python

Python bindings for the Myo SDK
Other
259 stars 102 forks source link

ctypes.util.find_library() did not manage to locate a library called 'name' #79

Closed nanyssalazar closed 4 years ago

nanyssalazar commented 5 years ago

Hello, I'm trying to run the Live Emg Python file, but its showing me this:

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cffi/api.py", line 822, in _load_backend_lib raise OSError(msg) OSError: ctypes.util.find_library() did not manage to locate a library called 'myo'

Does someone know how can I fix this?

shayanalibhatti commented 5 years ago

Did you install Myo SDK from Myo armband's website? Also check if path to library is correct

On Thu, Oct 3, 2019, 7:40 AM Andrea Salazar notifications@github.com wrote:

Hello, I'm trying to run the Live Emg Python file, but its showing me this:

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cffi/api.py", line 822, in _load_backend_lib raise OSError(msg) OSError: ctypes.util.find_library() did not manage to locate a library called 'myo'

Does someone know how can I fix this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NiklasRosenstein/myo-python/issues/79?email_source=notifications&email_token=AJY5TRPSS6EPAVKF7PCDANLQMXR4FA5CNFSM4I5CRSP2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPMRLFA, or mute the thread https://github.com/notifications/unsubscribe-auth/AJY5TRNZSKRUODW6PDW67KTQMXR4FANCNFSM4I5CRSPQ .

NiklasRosenstein commented 4 years ago

Hey @nanyssalazar ,

Did you get it working?

Temi-Tory commented 4 years ago

Hello, did you manage to resove this issue? I am struggling to load the myo32dll on python3.8. Keep getting an OSError

NiklasRosenstein commented 4 years ago

@Temi-Tory Can you share what steps you have taken when installing the Myo SDK in order for myo-python to find it?

Temi-Tory commented 4 years ago

I pip installed myo-python and did nto need to download another copy of SDK as i already had one in project folder. I am new to python as i am used to working within c# , so I am currently using visual studio to run the code ( so i dont know how to add path to be find the library).

However i tried going through Pycharm as well to addthe path to no avail. The steps i took on pycharm: Going to settings and tried adding the location of the myo32.dll file path to the current interpreter. Annotation 2020-04-19 155940

Temi-Tory commented 4 years ago

Hi, just a quick update, i have been able to get this working i think. following suggestion in the doc at https://github.com/NiklasRosenstein/myo-python/blob/master/docs/index.md#installation. I coppied the dll file and put in somwhere in my C: drive, Then imported the path directly in myo_init code like this:

from ctypes import * cdll.LoadLibrary("c:\myo32.dll")

****I'm using python 3.8.2

NiklasRosenstein commented 4 years ago

You don't need to copy the DLL, just pass the bin_path argument to myo.init() to where the DLL is.

import myo
myo.init(bin_path=r'C:\\path\\to\\myo-sdk\\bin')
vikramharindranath commented 4 years ago

Hello @NiklasRosenstein , I am trying to retrieve IMU data from Myo Armband. I have installed myo-python and downloaded the SDK too. Also i directed the bin's path to the environment variable.

When i run the program i want to execute, i get these errors.

line 475, in init error.raise_for_kind()

line 285, in raise_for_kind raise ResultError(kind, self.message) myo._ffi.ResultError: (<Result.error_runtime: 3>, b'Unable to connect to Myo Connect. Is Myo Connect running?'

Can you help me if possible?

shayanalibhatti commented 4 years ago

Hi,

It is probably because the Myo Connect from Desktop itself is not running. Please refer to my code. I make sure I exit the Myo Connect process and restart and make sure it is running properly from code itself. Before receiving data from Myo armband. Here is the link for my code. I hope that helps. The relevant lines are 79-95 and 292-298.

https://github.com/shayanalibhatti/Finger-Movement-Classification-via-Machine-Learning-using-EMG-Armband-for-3D-Printed-Robotic-Hand/blob/master/thesis_code_realistic_five_movements.py

Regards, Shayan Ali Bhatti.

On Wed, May 13, 2020 at 8:23 AM Sakthi Vikram notifications@github.com wrote:

Hello @NiklasRosenstein https://github.com/NiklasRosenstein , I am trying to retrieve IMU data from Myo Armband. I have installed myo-python and downloaded the SDK too. Also i directed the bin's path to the environment variable.

When i run the program i want to execute, i get these errors.

line 475, in init error.raise_for_kind()

line 285, in raise_for_kind raise ResultError(kind, self.message) myo._ffi.ResultError: (<Result.error_runtime: 3>, b'Unable to connect to Myo Connect. Is Myo Connect running?'

Can you help me if possible?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NiklasRosenstein/myo-python/issues/79#issuecomment-627982902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJY5TRLBPYAC7IEJD47JAVTRRKNNRANCNFSM4I5CRSPQ .

On Wed, May 13, 2020 at 8:23 AM Sakthi Vikram notifications@github.com wrote:

Hello @NiklasRosenstein https://github.com/NiklasRosenstein , I am trying to retrieve IMU data from Myo Armband. I have installed myo-python and downloaded the SDK too. Also i directed the bin's path to the environment variable.

When i run the program i want to execute, i get these errors.

line 475, in init error.raise_for_kind()

line 285, in raise_for_kind raise ResultError(kind, self.message) myo._ffi.ResultError: (<Result.error_runtime: 3>, b'Unable to connect to Myo Connect. Is Myo Connect running?'

Can you help me if possible?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NiklasRosenstein/myo-python/issues/79#issuecomment-627982902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJY5TRLBPYAC7IEJD47JAVTRRKNNRANCNFSM4I5CRSPQ .

vikramharindranath commented 4 years ago

Hello @shayanalibhatti

Thanks, But i still keep getting OS Error.

OSError: cannot load library 'C:\Path-to-MyoWindowsSDK\myo32.dll\myo32.dll': error 0x7e.

Any solutions for this? I have tried the above steps by fellow people too. I might have done it wrong but still an explanation once would be helpful since i am new to python.

shayanalibhatti commented 4 years ago

As I mentioned, is your Myo Connect running ? Go to Start -> Myo Connect ... check if it is running. Check in Task bar, you will see its icon. If this doesn't work. Add me on Skype shayanali_bhatti@hotmail.com. Maybe on screen share i might be able to help.

On Wed, May 13, 2020 at 9:13 AM Sakthi Vikram notifications@github.com wrote:

Hello @shayanalibhatti https://github.com/shayanalibhatti

Thanks, But i still keep getting OS Error.

OSError: cannot load library 'C:\Path-to-MyoWindowsSDK\myo32.dll\myo32.dll': error 0x7e.

Any solutions for this? I have tried the above steps by fellow people too. I might have done it wrong but still an explanation once would be helpful since i am new to python.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NiklasRosenstein/myo-python/issues/79#issuecomment-628017059, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJY5TRJEBS3VKW6LY6VNB5LRRKTJJANCNFSM4I5CRSPQ .

ryunosuke0723 commented 4 years ago

Hello, I'was trying to run the myo- Python file, but it happen same error : I have done installed myo-python and myo-connect: pip install myo-python This problem is about myo.init() I tried to some method that copy the myodll.64 to my file. But always it occur same error.
{cannot load library 'C:\path\to\myo-sdk\bin\myo64.dll': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\path\\to\\myo-sdk\\bin\myo64.dll' }

Please someone tell me how to fix it. Please.

chalgand commented 4 years ago

Hey @ryunosuke0723,

I used : myo.init(sdk_path=os.path.join('..', os.getcwd(), 'myo-sdk-win-0.9.0'))

My 2 cents

# -*- coding: utf-8 -*-
"""
Created on Tue Aug 28 18:12:10 2018

Ce code permet de récupérer un maximum d'informations issues d'un myo arm

@author: chalgand
"""

from collections import deque
from threading import Lock
import myo

class MyListener(myo.DeviceListener):
    """
    classe en écoute d'un myo
    """
    def __init__(self, queue_size=8):
        self.lock = Lock()  # verrouille le thread pour lecture des donnees
        # création de listes optimisées pour seulement ajouter des éléments
        self.emg_data_queue = deque(maxlen=queue_size)
        self.orientation_data_queue = deque(maxlen=queue_size)
        self.acceleration_data_queue = deque(maxlen=queue_size)
        self.gyroscope_data_queue = deque(maxlen=queue_size)
        self.rssi_data_queue = deque(maxlen=100)
        # initialisation d'attribut
        self.pose = myo.Pose.rest  # pose quelconque
        self.connected = False  # non connecté
        self.battery_level = 100  # niveau de batterie maximal
        self.emg_enabled = False  # on acquiert pas les EMG
        self.locked = False  # myo non vérouillé
        self.rssi = None  # aucune valeur de force du signal bluetooth
        self.emg = None  # données null des emg
        self.device_name = None  # pas de nom du myo
        self.device = None
        self.myo_firmware = None
        self.arm = None
        self.x_direction = None
        self.sync = None

    def on_paired(self, event):
        """
        méthode appelée si le myo est appareillé
        """
        if __name__ == '__main__':
            print('paired')
        else:
            pass

    def on_unpaired(self, event):
        """
        méthode appelée si le myo n'est plus appareillé
        """
        if __name__ == '__main__':
            print('unpaired')
        else:
            pass

    def on_connected(self, event):
        """
        méthode appelé si le myo est connecté
        """
        self.device = event.device  # sauvegarde de l'instance au myo arm
        event.device.unlock()  # demande de desappareiller
        event.device.lock()  # demande d'appareiller (génère des vibrations)
        event.device.stream_emg(True)  # lance l'acquisition des emg
        self.connected = True  # mise à jour du flag de connection du myo
        self.device_name = event.device_name  # on récupère le petit nom du myo
        # on récupère également le numéro du firmware (non exploité dans l'UI)
        self.myo_firmware = '.'.join(map(str, event.firmware_version[:-1]))

    def on_disconnected(self, event):
        """
        méthode appelée si le myo est déconnecté
        """
        self.connected = False  # flag mis à jour

    def on_arm_synced(self, event):
        """
        méthode appelé si un bras est synchronisé
        pas vraiment compris !!!
        """
        self.sync = True
        self.arm = event.arm  # informe de la latéralité du bras détecté
        # informe de l'orientation du bracelet
        # (vers le poignet ou vers le coude)
        self.x_direction = event.x_direction
        if __name__ == '__main__':
            print(self.x_direction)
        else:
            pass

    def on_arm_unsynced(self, event):
        """
        méthode appelée si le bras est désynchronisé
        pas vraiment compris !!!
        """
        self.sync = False
        if __name__ == '__main__':
            print(f'arm unsynced : {event.arm}')
        else:
            pass

    def on_unlocked(self, event):
        """
        méthode appelée si le myo est dévérouillé
        """
        self.locked = False  # flag mis à jour

    def on_locked(self, event):
        """
        méthode appelée si le myo est vérouillé
        """
        self.locked = True  # flag mis à jour

    def on_pose(self, event):
        """
        méthode appelée dès qu'une pose gestuelle est reconnue

            a) Spread
            b) Fist
            c) Wave in
            d) Wave out
            e) Double Tap
            f) Rest
        """
        self.pose = event.pose  # attribut mis à jour

    def on_orientation(self, event):
        """
        méthode appelée pour récupérer

            a) orientation
            b) gyroscope
            c) accéléromètre
            d) associé à un timestamp
        """
        with self.lock:
            self.orientation_data_queue.append((event.timestamp,
                                                event.orientation))
            self.gyroscope_data_queue.append((event.timestamp,
                                              event.gyroscope))
            self.acceleration_data_queue.append((event.timestamp,
                                                 event.acceleration))

    def on_rssi(self, event):
        """
        méthode appelée suite à la réponse d'une requête "request_rssi()"
        """
        with self.lock:
            # mise à jour de la liste
            self.rssi_data_queue.append(-event.rssi)

    def on_battery_level(self, event):
        """
        méthode appelée dès que le niveau de batterie évolue
        """
        self.battery_level = event.battery_level  # mise à jour de l'attribut

    def on_emg(self, event):
        """
        méthode appelée pour réceptionner les données EMG
        avec son timestamp
        """
        with self.lock:
            self.emg_data_queue.append((event.timestamp,
                                        event.emg))

    def on_warmup_completed(self, event):
        """
        méthode appelée quand le myo arm est "chaud"

        c'est à partir de ce moment que les données sont les plus stables
        mais ça reste à vérifier

        pas vraiment pris en compte dans ce code (à faire évoluer)
        """
        event.device.stream_emg(True)  # lancement de l'acquisition EMG
        self.emg_enabled = True  # mise à jour du flag

    def get_emg_data(self):
        """
        méthode pour récupérer les données EMGs
        """
        with self.lock:
            return list(self.emg_data_queue)

    def get_orientation_data(self):
        """
        méthode pour récupérer les données d'orientation
        """
        with self.lock:
            return list(self.orientation_data_queue)

    def get_gyroscope_data(self):
        """
        méthode pour récupérer les données du gyroscope
        """
        with self.lock:
            return list(self.gyroscope_data_queue)

    def get_accelerometor_data(self):
        """
        méthode pour récupérer les données de l'accéléromètre
        """
        with self.lock:
            return list(self.acceleration_data_queue)

if __name__ == '__main__':
    # permet de tester sans interface graphique
    import os
    from time import sleep
    myo.init(sdk_path=os.path.join('..',
                                   os.getcwd(),
                                   'myo-sdk-win-0.9.0'))
    HUB = myo.Hub()
    LISTENER = MyListener()
    with HUB.run_in_background(LISTENER.on_event):
        while True:
            print(LISTENER.emg_data_queue)
            sleep(0.02)
ryunosuke0723 commented 4 years ago

Hi@chalgand, thanks answering my question for me. First, i tried to share the libraly in command line.(import myo as libmyo →libmyo.init()) Next I tried implement cord which you wrote for me. I could do it. But another problem occured. 「hub.shutdown() AttributeError: 'Hub' object has no attribute ['shutdown'」] How can I fix it ?

myo.init() hub = myo.Hub() start = time.time() temp = [] try: listener = MyListener() hub.run(2000, listener) while True: data = listener.get_emg_data() if time.time() - start >= 1: response = np.argmax(np.bincount(temp)) print("Predicted gesture: {0}".format(response)) temp = [] start = time.time() if len(data) > 0: tmp = [] for v in listener.get_emg_data(): tmp.append(v[1]) tmp = list(np.stack(tmp).flatten()) if len(tmp) >= 64: pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])}) temp.append(pred[0]) time.sleep(0.01) finally: hub.shutdown() sess.close()

chalgand commented 4 years ago

https://myo-python.readthedocs.io/en/latest/myo.html#myo.Hub.shutdown

print(dir(hub))
ryunosuke0723 commented 4 years ago

But I still have problem. It is "attempt to get argmax of an empty sequence" How can I fix it ? import collections import myo import threading import time import numpy as np import tensorflow as tf from include.model import model

x, y, output, global_step, y_pred_cls = model()

saver = tf.train.Saver() _SAVE_PATH = "./data/tensorflow_sessions/myo_armband/" sess = tf.Session()

try: print("Trying to restore last checkpoint ...") last_chk_path = tf.train.latest_checkpoint(checkpoint_dir=_SAVE_PATH) print(last_chk_path) saver.restore(sess, save_path=last_chk_path) print("Restored checkpoint from:", last_chk_path) except: print("Failed to restore checkpoint. Initializing variables instead.") sess.run(tf.global_variables_initializer())

class MyListener(myo.DeviceListener):

def __init__(self, queue_size=8):
    self.lock = threading.Lock()
    self.emg_data_queue = collections.deque(maxlen=queue_size)

def on_connect(self, device, timestamp, firmware_version):
    device.set_stream_emg(myo.StreamEmg.enabled)

def on_emg_data(self, device, timestamp, emg_data):
    with self.lock:
        self.emg_data_queue.append((timestamp, emg_data))

def get_emg_data(self):
    with self.lock:
        return list(self.emg_data_queue)

myo.init(bin_path=r'C:\Users\田澤龍之介\Desktop\myo-sdk-win-0.9.0\bin') hub = myo.Hub() start = time.time() temp = [] try: listener = MyListener() hub.run(listener, 2000) while True: data = listener.get_emg_data() if time.time() - start >= 1: response = np.argmax(np.bincount(temp)) print("Predicted gesture: {0}".format(response)) temp = [] start = time.time() if len(data) > 0: tmp = [] for v in listener.get_emg_data(): tmp.append(v[1]) tmp = list(np.stack(tmp).flatten()) if len(tmp) >= 64: pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])}) temp.append(pred[0]) time.sleep(0.01) finally:

hub.shutdown()

sess.close()
ryunosuke0723 commented 4 years ago

Please tell me how to fix ? attempt to get argmax of an empty sequence?

2020年8月20日(木) 18:10 chalgand notifications@github.com:

https://myo-python.readthedocs.io/en/latest/myo.html#myo.Hub.shutdown

print(dir(hub))

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/NiklasRosenstein/myo-python/issues/79#issuecomment-677477534, or unsubscribe https://github.com/notifications/unsubscribe-auth/APQ3HWBEYFQVAUB2ZZQDUELSBTR63ANCNFSM4I5CRSPQ .

--

1512079 田澤龍之介 電気通信大学 情報理工学部 知能機械工学科 〒182-8585 東京都調布市調布ケ丘 1-5-1 Tel: 080-5902-8366 Email: maringan.gg41@gmail.com

NiklasRosenstein commented 4 years ago

This error has nothing to do with myo-python. Obviously it has something to do with your call to np.argmax(), passing in an empty sequence when the function expects a non-empty sequence.

crasgaitis commented 11 months ago

I'm having the same issue with the myo32dll file. I also don't see the file in the SDK. Where can I download it?