I'm building quite an extensive Python backend and things were working quite good on server A. I then installed the system on a new (development) server B on which I simply installed all pip packages again from scratch. Things seemed to work fine, so I did a pip freeze
. I then took that list and upgraded the packages on server A.
But, as you might expect I should have known better. I didn't test things on machine B wel enough, so I ran into a problem with Pillow version 3.0.0. So I downgraded to version 1.7.8. That solves that single problem, bug gives me another one:
File "/home/kramer65/theproject/app/models/FilterResult.py", line 26, in to_json
self.image.save(b, 'JPEG')
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1437, in save
save_handler(self, fp, filename)
File "/usr/local/lib/python2.7/dist-packages/PIL/JpegImagePlugin.py", line 471, in _save
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 476, in _save
fh = fp.fileno()
UnsupportedOperation: fileno
And here I'm kinda lost. As far as I know this is a problem in Pillow itself, so I wouldn't know why it used to work and why it doesn't work anymore.
I searched around on the internet, but I couldn't find any solution.
Does anybody know what I could do to solve this?
ps. PIL is not installed, so it's not a collision between PIL and Pillow
[EDIT]
I just tested an import Image
in Python (which would suggest that PIL is still installed). To my surprise that succeeds, even though pip tells me that it is not installed:
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> exit()
$ sudo pip uninstall PIL
The directory '/home/hielke/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Cannot uninstall requirement PIL, not installed
BytesIO
objects raiseUnsupportedOperation
(rather thanAttributeError
whichStringIO
does) when theirfileno
method is called that exception wasn't handled as it should be.This was fixed in Pillow 3.0.0 by this commit https://github.com/python-pillow/Pillow/commit/197885164b22f82653af514e66c76f4b778c0b1b by catching the exception. The following is the fix. The rest of that commit are changes to the test suite.
In
PIL/ImageFile.py
:You could simply patch 1.7.8 to handle the exception.
I finally managed to fix things. The reason I downgraded pillow from 3.0.0 to 1.7.8, is because those where the only two versions I saw listed on the Pillow Pypi package index. I finally remembered that I had one more server on which I once tested this code and there it was still working. A quick
pip freeze
told me that it had Pillow version2.3.0
installed. So after installing that on my dev server things worked beautifully again.So what have I learned from this? Use
pip freeze
!