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

PIL TypeError #122

Closed
PhilP88 opened this issue Apr 14, 2022 · 9 comments
Closed

PIL TypeError #122

PhilP88 opened this issue Apr 14, 2022 · 9 comments

Comments

@PhilP88
Copy link

PhilP88 commented Apr 14, 2022

Hi,
I constantly get a TypeError when trying to run gui.py.

Traceback (most recent call last):
  File "/Applications/LaTeX-OCR-main/gui.py", line 266, in mouseReleaseEvent
    img = ImageGrab.grab(bbox=(x1, y1, x2, y2), all_screens=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/ImageGrab.py", line 42, in grab
    im_resized = im.resize((right - left, bottom - top))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 2040, in resize
    im = im.resize(size, resample, box)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 2062, in resize
    return self._new(self.im.resize(size, resample, box))
TypeError: integer argument expected, got float
zsh: abort      '/usr/local/bin/python3.8' '/Applications/LaTeX-OCR-main/gui.py'
phil@Air-von-Phil LaTeX-OCR-main % 

Pix2Tex works, even though I get an unsupported hardware notification.
I'm on a M1 MacBook Air. Any help would be great.
Kind regards

@lukas-blecher
Copy link
Owner

Hi Phil,
I think this might be related to the retina display #118. Can you tell me what PIL version you have installed.
if is not the latest (9.1.0) try to downgrade to e.g. 9.0.1 and try again.
If it is, can you do some experiments for me? I don't have a MacBook at hand:

  • what resolution does your display have?
  • what is the result of the following python snippets?
    from PIL import ImageGrab
    print(ImageGrab.grab().size)
  • move your mouse to the lower right corner and execute
    from pynput.mouse import Controller
    m = Controller()
    print(m.position)

@PhilP88
Copy link
Author

PhilP88 commented Apr 14, 2022

Downgrading PIL stopped it from crashing but all the values are incorrect. The windows version, a little older, gets most of the snips right.
I copy the windows version and see what will happen.

The other questions, that might help others:

My Display is 13.3 with a resolution of 2560 x 1600

from PIL import ImageGrab
print(ImageGrab.grab().size)
>>> (2880, 1800)
from pynput.mouse import Controller
m = Controller()
print(m.position)
>>> (1439.98046875, 899.98046875)

Thanks

@lukas-blecher
Copy link
Owner

The windows version, a little older, gets most of the snips right. I copy the windows version and see what will happen.

What do you mean by that?

from PIL import ImageGrab
print(ImageGrab.grab().size)
>>> (2880, 1800)
from pynput.mouse import Controller
m = Controller()
print(m.position)
>>> (1439.98046875, 899.98046875)

Just to be sure with which PIL version did you execute this? Can you also post the result for the other one?
Sorry of the back and forth.

lukas-blecher added a commit that referenced this issue Apr 14, 2022
ensure int for bbox #122
@PhilP88
Copy link
Author

PhilP88 commented Apr 14, 2022

I got the MacBook few months ago but was using the application on windows for much longer and I still have all the data from the windows version. I copy it over to my mac and redo everything again and see what happens.

I downgraded the PIL version to 9.0.1 just like suggested. The result of PIL 9.1.0 was posted in the initial post. The values from the code snippets didn't change.

lukas-blecher added a commit that referenced this issue Apr 15, 2022
@lukas-blecher
Copy link
Owner

That shouldn't help. The correct way to install the repo has changed since you first started using it. You can simply call pip install pix2tex. There have been quite a few improvements and bugfixes since (including 3e610fd which is a start for your problem).

The problem is definitely related to the retina display. Can you also tell me what the result is of

from screeninfo import get_monitors
print(get_monitors())

and also

import tkinter as tk
root = tk.Tk()
print(root.winfo_screenwidth(), root.winfo_screenheight())

One of the two libraries (PIL and pynput) is working with the wrong display size. I don't really want to do a hot fix in my repo but what can I do.
Try to install the repo as described above and try to snip something. It might work now in ae9ed4f (0.0.11)

@PhilP88
Copy link
Author

PhilP88 commented Apr 15, 2022

from screeninfo import get_monitors
print(get_monitors())
>>> [Monitor(x=0, y=0, width=1440, height=900, width_mm=None, height_mm=None, name=None, is_primary=True)]

import tkinter as tk
root = tk.Tk()
print(root.winfo_screenwidth(), root.winfo_screenheight())
>>> 1440 900

The update installs/updates Pillow to 9.1.0 which results in the error from the beginning. I'll keep using it on windows for now.
Thanks

@lukas-blecher
Copy link
Owner

But have you tried the latest version? I think it might work for you.

@PhilP88
Copy link
Author

PhilP88 commented Apr 15, 2022

No I haven't tried it yet, since misread some of the post. Didn't know that pix2tex is now a module. I'll try it tomorrow.

@lukas-blecher
Copy link
Owner

I'm closing this for now. Feel free to reopen if the issue persists

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

No branches or pull requests

2 participants