Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PsychoPy and PIL incompatibility #991

Closed
fnielsen opened this issue Nov 4, 2015 · 12 comments

Comments

Projects
None yet
5 participants
@fnielsen
Copy link

commented Nov 4, 2015

When I try to start with psychopyApp.py I get a error message with PIL.

  File "/usr/local/lib/python2.7/dist-packages/psychopy/app/builder/components/__init__.py", line 21, in pilToBitmap
    image.SetData( pil.convert( "RGB").tostring() )
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 686, in tostring
    "Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.

I do not see any requirements.txt in the psychopy package. When I reinstall PsychoPi with sudo pip install --upgrade --force-reinstall psychopy I do not get other packages installed.

I am running these version:
>>> import PIL
>>> PIL.VERSION, PIL.PILLOW_VERSION
('1.1.7', '3.0.0')
>>> import psychopy
>>> psychopy.version
'1.82.01'

@fnielsen

This comment has been minimized.

Copy link
Author

commented Nov 5, 2015

As a workaround I installed PsychoPy as a user package and went to ~/.local/lib/python2.7/site-packages/psychopy/app/builder/components/__init__.py. I changed

 21     image.SetData( pil.convert( "RGB").tostring() )
 22     image.SetAlphaData(pil.convert("RGBA").tostring()[3::4])

to

 21     image.SetData( pil.convert( "RGB").tobytes() )
 22     image.SetAlphaData(pil.convert("RGBA").tobytes()[3::4])

I suppose a try/except would better accommodate PIL differences.

@peircej

This comment has been minimized.

Copy link
Member

commented Nov 5, 2015

Actually this has already been done in the repository code (in commit 19ac073 )
thanks though! :-)

@peircej peircej closed this Nov 5, 2015

@fnielsen

This comment has been minimized.

Copy link
Author

commented Nov 5, 2015

Thanks. I suppose one should always take a glance at the repository code. :-)

@brittAnderson

This comment has been minimized.

Copy link

commented Nov 19, 2015

Would like to know if this is basically the same issue. I am trying to run a demo that used to work, but now fails with:

Traceback (most recent call last):
  File "plinkoDemo.py", line 130, in <module>
    plinkoTable = visual.BufferImageStim(win) 
  File "/usr/lib/python2.7/site-packages/PsychoPy-1.83.1-py2.7.egg/psychopy/contrib/lazy_import.py", line 120, in __call__
    return obj(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/PsychoPy-1.83.1-py2.7.egg/psychopy/visual/bufferimage.py", line 134, in __init__
    region = win._getRegionOfFrame(buffer=buffer, rect=rect)
  File "/usr/lib/python2.7/site-packages/PsychoPy-1.83.1-py2.7.egg/psychopy/visual/window.py", line 950, in _getRegionOfFrame
    im = Image.fromstring(mode='RGBA', size=(horz, vert), data=bufferDat)
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 2053, in fromstring
    "Please call frombytes() instead.")
Exception: fromstring() has been removed. Please call frombytes() instead.
Exception AttributeError: "'BufferImageStim' object has no attribute '_texID'" in <bound method BufferImageStim.__del__ of <psychopy.visual.bufferimage.BufferImageStim object at 0x7f3378d545d0>> ignored
0.7322  WARNING     Monitor specification not found. Creating a temporary one...

When I down grade Pillow from 3.0 to 2.9 the code now executes. Seems to be a problem with the fromstring.

@fnielsen

This comment has been minimized.

Copy link
Author

commented Nov 19, 2015

Release 1.83.01 is from 19 October while the critical commit is from 21 October, so it might be. You could git clone git@github.com:psychopy/psychopy.gitto see if it helps.

@hoechenberger

This comment has been minimized.

Copy link
Member

commented Nov 20, 2015

@brittAnderson This should be the very same issue, yes.

@LGurtner

This comment has been minimized.

Copy link

commented Apr 1, 2016

I am receiving a similar error, could it be the same reason? And what could I do about it?
Thanks for any help!

Here is the error (I am new to GitHub and don't know how to make it easier to read, sorry!):

Traceback (most recent call last):
File "/Users/lilla/PycharmProjects/binocular rivalry/pretest_luminance/p_RUN_LUMINANCE_WRAPPER.py", line 47, in
Test.run_trials(5,20) #50 real trials, 20 fake ones
File "/Users/lilla/PycharmProjects/binocular rivalry/pretest_luminance/p_Run_TestColors.py", line 523, in run_trials
screenshot = visual.BufferImageStim(self.screen, stim=Stimlist, rect = rect, mask = 'gauss', pos=(0.0, 0.0))
File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/contrib/lazy_import.py", line 120, in call
return obj(_args, *_kwargs)
File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/bufferimage.py", line 134, in init
region = win._getRegionOfFrame(buffer=buffer, rect=rect)
File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/window.py", line 939, in _getRegionOfFrame
GL.glReadBuffer(GL.GL_BACK)
File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/pyglet/gl/lib.py", line 104, in errcheck
raise GLException(msg)
pyglet.gl.lib.GLException: invalid operation
Exception AttributeError: "'BufferImageStim' object has no attribute '_texID'" in <bound method BufferImageStim.del of <psychopy.visual.bufferimage.BufferImageStim object at 0x115edd2d0>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'platform'" in <bound method Window.del of <psychopy.visual.window.Window object at 0x11370e850>> ignored

@brittAnderson

This comment has been minimized.

Copy link

commented Apr 1, 2016

I downgraded PILLOW. If it is the same problme this should work. You could check if you have PILLOW 3. And if so, downgrade to <3. How you do this will depend on how you got PILLOW in the first place (this is a python imaging library that is, I believe, a fork of PIL). On my Linux it lives in /usr/lib/python2.7/site-packages/ . If you used PIP to install it (or easy_setup) there is probably some way to check the version (some python packages will also put the version information in a string somewhere, but it is not always consistent). With PIP (or for me pip2) you can install a specific version. This stackoverflow answer has some hints: http://stackoverflow.com/questions/5226311/installing-specific-package-versions-with-pip
If you are not on Linux then others will have to help.

@peircej

This comment has been minimized.

Copy link
Member

commented Apr 1, 2016

@LGurtner your error looks entirely different. I don't think downgrading Pillow/PIL will help. But this issue is closed because the recent releases of PsychoPy shouldn't show the problem any more anyway.

Your error seems to be the graphics card not being willing to read back from the rendering buffer (ie. looks like driver problem). What is your graphics card and have you updated the drivers?

@LGurtner

This comment has been minimized.

Copy link

commented Apr 4, 2016

@peircej Should I open a new issue then? I am not sure of the best practice here, sorry!
My graphics card is Intel Iris Pro 1536 MB on OS X el Capital 10.11.1. The bufferImageStim was my attempt to fix a strange behavior of Psychopy: Drawing 4 Gratingstims would work for 1 frame but then the position of the stimuli would change (not so however the pos-argument of GratingStim) and remain on the new location every time that same stimulus was drawn. Unfortunately I was unable to recreate that outside of my long script... Thanks for your help and advice on the issue opening thing!

@peircej

This comment has been minimized.

Copy link
Member

commented Apr 4, 2016

At the moment we don't know if this is an issue with PsychoPy or an
issue with your code. If you can't recreated the problem outside your
long script then your code might well be the problem. For us to work out
what's going on you'll need to create a "minimal example" that generates
the error (i.e. just enough code to demonstrate the problem). I'd
suggest you send that to the mailing list thoughwhere more people will
see it.

if we can confirm that it's an issue with PsychoPy that we need to fix
then it's time to add a new issue here

cheers
Jon

This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it.

Please do not use, copy or disclose the information contained in this
message or in any attachment. Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

@LGurtner

This comment has been minimized.

Copy link

commented Apr 4, 2016

ok, I will try to do that, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.