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

im.show: AttributeError: 'int' object has no attribute 'write' #3517

Closed
hugovk opened this issue Dec 30, 2018 · 3 comments
Closed

im.show: AttributeError: 'int' object has no attribute 'write' #3517

hugovk opened this issue Dec 30, 2018 · 3 comments

Comments

@hugovk
Copy link
Member

hugovk commented Dec 30, 2018

What did you do?

im.show() on Mac.

What did you expect to happen?

It to show the image in Preview.app.

What actually happened?

Traceback (most recent call last):
  File "1.py", line 3, in <module>
    im.show()
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2035, in show
    _show(self, title=title, command=command)
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2900, in _show
    _showxv(image, **options)
  File "/Users/hugo/github/Pillow/src/PIL/Image.py", line 2905, in _showxv
    ImageShow.show(image, title, **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 53, in show
    if viewer.show(image, title=title, **options):
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 77, in show
    return self.show_image(image, **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 97, in show_image
    return self.show_file(self.save_image(image), **options)
  File "/Users/hugo/github/Pillow/src/PIL/ImageShow.py", line 136, in show_file
    f.write(file)
AttributeError: 'int' object has no attribute 'write'

What are your OS, Python and Pillow versions?

  • OS: macOS High Sierra
  • Python: 3.7.1 and 2.7.15
  • Pillow: master
from PIL import Image
im = Image.new("RGB", (200, 100))
im.show()

Cannot reproduce with last Pillow release 5.3.0.

@hugovk
Copy link
Member Author

hugovk commented Dec 30, 2018

git bisect points to fea3daf from #3450.

1.sh:

python3 setup.py clean
make clean
python3 setup.py develop
python3 1.py

1.py:

from PIL import Image
im = Image.new("RGB", (200, 100))
im.show()
git bisect start
git bisect good 5.3.0
git bisect bad master
git bisect run sh 1.sh
Finished processing dependencies for Pillow==5.4.0.dev0
fea3dafd05c8ca44c30167c34ce4d82964421efb is the first bad commit
commit fea3dafd05c8ca44c30167c34ce4d82964421efb
Date:   Sat Nov 3 14:24:10 2018 +1100

    Supply filename through stdin instead of inline in Mac and Unix ImageShow viewers

:040000 040000 8b9b5c67f53dcc6a67c3d370aa98a022d3a710d8 db2ec6e164b854dc0f30e72f7816a5dccc741aa8 M	src
bisect run success

@hugovk
Copy link
Member Author

hugovk commented Dec 30, 2018

Pillow/src/PIL/ImageShow.py

Lines 133 to 146 in 37d61f1

def show_file(self, file, **options):
"""Display given file"""
f, path = tempfile.mkstemp()
f.write(file)
f.close()
with open(path, "r") as f:
subprocess.Popen([
'im=$(cat);'
'open -a /Applications/Preview.app $im;'
'sleep 20;'
'rm -f $im'
], shell=True, stdin=f)
os.remove(path)
return 1

f, path = tempfile.mkstemp()

returns:

3 /var/folders/kt/j77sf4_n6fnbx6pg199rbx700000gn/T/tmp_cn1hw21

@radarhere
Copy link
Member

Hmm. Apologies, I'm surprised that I apparently didn't test this properly at the time. I've created PR #3518 to resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants