Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Unable to draw annotations on Windows #811

Open
zaitsman opened this issue Nov 18, 2021 · 25 comments
Open

Unable to draw annotations on Windows #811

zaitsman opened this issue Nov 18, 2021 · 25 comments

Comments

@zaitsman
Copy link

I installed Python 3.10, PyQt5 and libxml using instructions in readme. md

I used pyrcc5 to create resources.qrc successfully.

The UI loads, and I can get to my folder, and see my images. As soon as I try creating an annotation (pressed W on my keyboard) the script crashes with the following log

Traceback (most recent call last):
  File "C:\Users\whoever\AppData\Local\Programs\Python\Python310\Apps\labelImg-master\labelImg-master\libs\canvas.py", line 530, in paintEvent
    p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
TypeError: arguments did not match any overloaded call:
  drawLine(self, QLineF): argument 1 has unexpected type 'float'
  drawLine(self, QLine): argument 1 has unexpected type 'float'
  drawLine(self, int, int, int, int): argument 1 has unexpected type 'float'
  drawLine(self, QPoint, QPoint): argument 1 has unexpected type 'float'
  drawLine(self, Union[QPointF, QPoint], Union[QPointF, QPoint]): argument 1 has unexpected type 'float'
  • OS: Windows 10
  • PyQt version: 5

Same thing works a treat on mac os.

@Bouffard94
Copy link

Bouffard94 commented Nov 19, 2021

Same issue here since I installed labelImg last week. Windows 10.

@sammiee5311
Copy link
Contributor

sammiee5311 commented Nov 24, 2021

@zaitsman I think you can either downgrade python version(< 3.10) or change some values' type manually.

For me, I reinstalled python 3.9 and it worked well.

change float to int

You can change the type from float to int and it works but it omits other errors.

( I think the problem is that drawLine method takes int type, but the x function returns float type as well as setValue method ? )

@pradoz
Copy link

pradoz commented Dec 19, 2021

switching back to python 3.9 worked for me. thanks @sammiee5311

@YanisSadou
Copy link

YanisSadou commented Dec 26, 2021

Hi guys, I have the same problem! But I don't know where is the 'float' to change into an 'int' in the file about @sammiee5311 talked about. (line 530, 531 etc...)

And if someone would explain to me how to downgrade the python version 3.10 to 3.9 as @pradoz said above with cmd.

This is the canvas.py file
Capture

@sammiee5311
Copy link
Contributor

sammiee5311 commented Dec 26, 2021

Hi guys, I have the same problem! But I don't know where is the 'float' to change into an 'int' in the file about @sammiee5311 talked about. (line 530, 531 etc...)

And if someone would explain to me how to downgrade the python version 3.10 to 3.9 as @pradoz said above with cmd.

This is the canvas.py file Capture

@YanisSadou, You can replace
from p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
to p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
due to values which are float.

However, It does not fix everything so there will be other problems while working with it.

So I recommend you to switch the python version.

First, install any python version lower than 3.10.

Then, If you use windows os, you can change windows PATH system variables to make reordering python versions.

or you can use virtualenv

<your pip version> install virtualenv
virtualenv --python=<python version> venv
  • example
pip3 install virtualenv
virtualenv --python=3.9 venv (or python3 -m virtualenv --python=3.9 venv)

and then install dependencies what you want in the python virtual environment.

@YanisSadou
Copy link

YanisSadou commented Dec 26, 2021

@sammiee5311 I just replace some lines in the canvas.py thanks to your advice, change all 'float' to 'int':

  1. canvas.py#L526
  2. canvas.py#L530
  3. canvas.py#L531
  4. labelImg.py#L965

It seems to work well. You are a goat!

@sammiee5311
Copy link
Contributor

@YanisSadou No worries !

@tzutalin
Copy link
Contributor

Hi
Seems windows qt has a problem. I will make changes to fix it according to @YanisSadou changes

@sammiee5311
Copy link
Contributor

@tzutalin I think you need to change more than 4 lines that @YanisSadou replaced.

I don't have a laptop right now. There are another lines need to be fixed in order not to get errors while using it.

Because lots of methods returns float instead int.

@tzutalin
Copy link
Contributor

tzutalin commented Dec 27, 2021

@sammiee5311 ,

could you help submit a PR for this bug since I cannot reproduce this on my mac.

Basically, I guess it should have converted to int before calling QT methods like drawLine. We probably don't need to convert all floats to int. We can keep them. Instead, changing the float to int before calling QT's methods

Thanks in advance!

@sammiee5311
Copy link
Contributor

sammiee5311 commented Dec 27, 2021

@tzutalin, Sure !

I will submit a PR after my work done.

I have one question that

Instead, changing the float to int before calling QT's methods

you meant, change like p.drawLine(self.prev_point.x(), ...) to p.drawLine(int(self.prev_point.x()), ...) ?

@tzutalin
Copy link
Contributor

Thanks. ya~ I was thinking about this which is the same as you post above

@sammiee5311
Copy link
Contributor

@tzutalin No worries ! Okay, good :)

@YakaTouji
Copy link

can you give me the result of changing the int? i dont know how to change it
i mean the source code after it

@sammiee5311
Copy link
Contributor

Hello, @YakaTouji

I think you can follow this comment ?

@SyrusBG
Copy link

SyrusBG commented Aug 2, 2022

created a new venv using python 3.8 and then pip3 install labelImg then simply type labelImg in the terminal

@richeym-umich
Copy link

Also have this issue- when can we expect this to be upgraded to work with Python 3.10?

@garrettkajmowicz
Copy link

I'm hitting the same thing after upgrading to Ubuntu 22.04 LTS
Python 3.10.6
pip 22.0.2
PyQt5 5.15.6

@LOKESH-999
Copy link

Hello i to have the same problem, But i don't know where to fix it & how too

@ghost
Copy link

ghost commented Jan 20, 2023

Hello i to have the same problem, But i don't know where to fix it & how too

Try downgrading python to version 3.9. From what I saw, it solved almost everyone's problems in my contacts.

@richeym-umich
Copy link

Are there any updates on when this will be upgraded to python 3.10? I have many pipelines that have been using 3.10 for a while, but I have to separate this part out to use python 3.9, which is a lot of extra work.

@LOKESH-999
Copy link

LOKESH-999 commented Jan 21, 2023 via email

@Michaelian624
Copy link

I use anaconda to create a virtual environment like python 3.9 or python3.7
But the error still exists
Do I need to install labelimg in the virtual environment?

@weiweijeff
Copy link

argument 1 has unexpected type 'float', that means it should be 'int' type.
p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))

@clodoaldocodes
Copy link

I made a post talking about how to solve this problem step-by-step, maybe it will help you.
https://stackoverflow.com/questions/76937982/labelimg-closes-when-attempting-to-label-error-in-canvas-py-file/77891276#77891276

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

No branches or pull requests