openbci-archive / OpenBCI_Python

The Python software library designed to work with OpenBCI hardware.
MIT License
510 stars 207 forks source link

NameError: global name 'Peripheral' is not defined #103

Closed aliraza19 closed 5 years ago

aliraza19 commented 6 years ago

Basically we are trying to connect our Ganglion device to python so we can build a real time application in python. We have checked our device in Open_BCI GUI linux and its connecting properly. we are trying to connect Ganglion device with OpenBCI_Python through linux using user.py but eventually ended up in a error named "NameError: name 'Peripheral' is not defined" in terminal . Can anyone help us to resolve it?

Specifications: Ubuntu 18.04 LTS Open_BCI Python downloaded and installed from github Link: (https://github.com/OpenBCI/OpenBCI_Python) Installed all Requirements Link: (https://github.com/OpenBCI/OpenBCI_Python/blob/master/requirements.txt) Python 3.6 and 2.7 pip3 and 2

Error details: Picture in link: https://ibb.co/cnE4Sf (Avoid semi colon in end, simply copy till 'f' and paste in browser)

  1. It seems it is related to bluepy.btle
  2. Tested with root privileges.

Solution Tried:

  1. Different version of python (i.e 2.7 version)
  2. Installed package using pip2 as well.
  3. Installed updated version of bluepy to test. link: (https://github.com/IanHarvey/bluepy)
  4. Tested on different system i.e Ubuntu 16.04 LTS on different pc but encountered same error in the end.

Extra information: 1.Device mac address shows in Hci tool le scan.

  1. Device works properly with windows.

Please suggest some solution to our problem or an alternate way to connect our Ganglion device with python for application building.

aliraza19 commented 6 years ago

The problem is similar to the problem mentioned in Issue 87.. As mentioned in issue 87 , I tried to comment out the specified line sys.path.insert(0,"bluepy/bluepy") but no luck.

from bluepy.btle import Scanner, DefaultDelegate, Peripheral It says peripheral is not defined in error. So What do we define, or what is being missed here? Please tell me how to be sure that python external libraries are correctly loaded.

I am working with built-in version of python (2.7) right now and I am sure that this is not any hardware issue. I Installed all mentioned requirements with specified version and checked the code in Open BCI_Python Ganglion.py which seems alright.

wjcroft commented 6 years ago

Ali, thanks for logging this issue. HOWEVER, can you edit the title to be more accurate and descriptive to the exact error, which is: "NameError: global name 'Peripheral' is not defined". This is the same error that is showing up in the related issue 87.

ikmckenz commented 6 years ago

I replicated this bug with a minimal example below:

from ganglion import OpenBCIGanglion

driver = OpenBCIGanglion(port="TEST")

Running this produces:

Traceback (most recent call last):
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/test.py", line 3, in <module>
    driver = OpenBCIGanglion(port="AUTO")
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 94, in __init__
    self.connect()
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 121, in connect
    self.gang = Peripheral(self.port, 'random') # ADDR_TYPE_RANDOM
NameError: global name 'Peripheral' is not defined

When we expect some error about "TEST" not being a MAC address.

I think I see the bug, it relates to the somewhat messy way that BluePy is imported.

wjcroft commented 6 years ago

Ian, thanks. @andrewjaykeller, can you edit the title of this issue as I mentioned in the previous post? Title of issue should be (or at least include): "NameError: global name 'Peripheral' is not defined", which is also showing up in issue 87.

ikmckenz commented 6 years ago

Hey @aliraza19 and @basophobic , can you test out my patch in pull request #105 above and tell us if it resolves this specific problem for you?

aliraza19 commented 6 years ago

First of all thanks ikm for providing a helpful suggestion. As you mentioned in pull request #105 , i edited my code in ganglion.py accordingly but fortunately landed on ValueError: Expected MAC address, got '' . As soon as i test it with ganglion device i will update.

ikmckenz commented 6 years ago

Perfect, it sounds like we resolved that specific bug for you. If you find another bug please create a new issue for it (after researching to confirm it's a bug).

aliraza19 commented 5 years ago

Yes issue is resolved and we ended up in error ' plugins not found' device now connect but is unable to load plug-in. I am soon going to create a new issue for it after studying the problem in more detail. Thanks Stay in touch :+1:

ikmckenz commented 5 years ago

Hey @andrewjaykeller I think you can close this issue as it was resolved in #105 .

daniellasry commented 5 years ago

Resolved by #105