gpt4 book ai didi

python - 不支持的操作 : fileno - How to fix this Python dependency mess?

转载 作者:行者123 更新时间:2023-11-28 21:49:34 24 4
gpt4 key购买 nike

我正在构建一个相当广泛的 Python 后端,并且在服务器 A 上运行良好。然后我将系统安装在一个新的(开发)服务器 B 上,我只是从头开始重新安装所有 pip 包。事情似乎工作正常,所以我做了一个 pip freeze。然后,我获取了该列表并升级了服务器 A 上的软件包。

但是,正如您所料,我应该更清楚。我没有在机器 B 上测试得足够好,所以我遇到了 Pillow 3.0.0 版的问题。所以我降级到1.7.8版本。这解决了那个单一的问题,错误给了我另一个问题:

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

我有点迷路了。据我所知,这是 Pillow 本身的一个问题,所以我不知道为什么它过去可以工作,为什么不再工作。

我在网上四处搜索,但找不到任何解决方案。

有人知道我能做些什么来解决这个问题吗?

附言。 PIL没有安装,所以不是PIL和Pillow的碰撞

[编辑]

我刚刚在 Python 中测试了一个import Image(这表明 PIL 仍然被安装)。令我惊讶的是成功了,尽管 pip 告诉我它没有安装:

$ 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 对象在它们的 fileno 方法被调用,但未按应有的方式处理异常。

此提交已在 Pillow 3.0.0 中修复此问题 https://github.com/python-pillow/Pillow/commit/197885164b22f82653af514e66c76f4b778c0b1b通过捕获异常。以下是修复。该提交的其余部分是对测试套件的更改。

PIL/ImageFile.py 中:

 @@ -29,6 +29,7 @@

import Image
import traceback, os
+import io

MAXBLOCK = 65536

@@ -475,7 +476,7 @@ def _save(im, fp, tile):
try:
fh = fp.fileno()
fp.flush()
- except AttributeError:
+ except (AttributeError, io.UnsupportedOperation):
# compress to Python file-compatible object
for e, b, o, a in tile:
e = Image._getencoder(im.mode, e, a, im.encoderconfig)

您可以简单地修补 1.7.8 来处理异常。

关于python - 不支持的操作 : fileno - How to fix this Python dependency mess?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33285330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com