Egi library and python3

Hi,

The egi (egi.simple) library works fine if I use a python2 version of PsychoPy (e.g. 1.90.3), but if I try to use a recent version (one that is built on python3) I get the following error:

Traceback (most recent call last):
  File "C:\gpsy3\tasks\re_oddball_egi.py", line 16, in <module>
    import egi.simple as egi
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\egi\simple.py", line 347
    type(1L): ('long', '=l'),  # '=' -- translation is: four bytes
          ^
SyntaxError: invalid syntax

Anyone has any ideas how to solve this, or is the egi library simple incompatible with python3?

Thanks!

Yes, in Python 2 has two integer types, int and long. in Python 3, all integers are long integers:

http://python3porting.com/differences.html#long

To fix, the egi code will need to be made compatible for Python 3 installations i.e., not stating whether int is long. The link provided has potential fixes, and perhaps this can go on GitHub as an issue, considering @jon is the maintainer of egi:

Would you like to attempt to fix and test this?

Here is a start, should address the issue in your original post. You would have to overwrite the existing version of simple.py in your psychopy installation. Try this and see if it solves your problem.

simple.py (25.5 KB)

Hi, I already tried something like this but gave up somewhere in the middle. Your .py file has mixed tabs and spaces for offsets, after fixing this I get the same error as before.

It seems like this python checks for this before running any of the code, the condition sys.version_info[0] < 3 never gets checked, because errors are now in pieces of code that python3 should never get to (since sys.version_info[0] == 3).

If I remove all the code that is meant for pythons lower than 3 and only keep the two pieces that run if sys version is 3 or greater, I get a different error:

  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/egi/simple.py", line 4, in <module>
    from socket_wrapper import Socket
ModuleNotFoundError: No module named 'socket_wrapper'

Cheers!

Ah I forgot to change from socket_wrapper import Socket to from .socket_wrapper import Socket as this is python3 now.

It imports now, I will try running it on a NetStation later this week, will let you know how it goes.

Great thanks. Yes, apologies for the formatting error, I was not using my normal text editor :slight_smile:

I tried to run the experiment today with the manually updated library but it does not work. The experiment crashes when I try to start the session via net station:

Traceback (most recent call last):
  File "C:\gpsy3\tasks\oddball_egi.py", line 207, in <module>
    net_station.BeginSession
  File "..\libs\egi\simple.py", line 641, in BeginSession
    message = self._fmt.pack('Q', self._system_spec)
  File "..\libs\egi\simple.py", line 248, in pack
    result = struct.pack(fmt, key, *args)
struct.error: char format requires a bytes object of length 1

I raised an issue on the https://github.com/gaelen/python-egi, until it gets resolved we will just use an old version of PsychoPy (everything works as it should on 1.90.3).

1 Like

Has anyone made any progress with this issue? I am running into the same problem with trying to run egi library with python 3 @gstothart

Hi everyone, just a heads up that we have nearly finished updating the egi library to work with Python 3. We’ve got it working and are just documenting all the changes we’ve made. I’ll post it up here hopefully in the next week or so, @jon you’re welcome to include it in the new releases of Psychopy.
Cheers
George

What is the status of egi python 3 update mentioned in above post?

Hi, we’ve just put it up on Github, see https://github.com/gstothart/EGI-Psychopy-Python3