labelImg icon indicating copy to clipboard operation
labelImg copied to clipboard

Unable to draw annotations on Windows

Open zaitsman opened this issue 3 years ago • 25 comments

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.

zaitsman avatar Nov 18 '21 02:11 zaitsman

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

Bouffard94 avatar Nov 19 '21 17:11 Bouffard94

@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 ? )

sammiee5311 avatar Nov 24 '21 07:11 sammiee5311

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

pradoz avatar Dec 19 '21 18:12 pradoz

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 avatar Dec 26 '21 13:12 YanisSadou

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.

sammiee5311 avatar Dec 26 '21 13:12 sammiee5311

@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!

YanisSadou avatar Dec 26 '21 21:12 YanisSadou

@YanisSadou No worries !

sammiee5311 avatar Dec 27 '21 00:12 sammiee5311

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

tzutalin avatar Dec 27 '21 01:12 tzutalin

@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.

sammiee5311 avatar Dec 27 '21 02:12 sammiee5311

@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!

tzutalin avatar Dec 27 '21 04:12 tzutalin

@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()), ...) ?

sammiee5311 avatar Dec 27 '21 06:12 sammiee5311

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

tzutalin avatar Dec 27 '21 07:12 tzutalin

@tzutalin No worries ! Okay, good :)

sammiee5311 avatar Dec 27 '21 08:12 sammiee5311

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

YakaTouji avatar Jun 18 '22 10:06 YakaTouji

Hello, @YakaTouji

I think you can follow this comment ?

sammiee5311 avatar Jun 19 '22 10:06 sammiee5311

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

SyrusBG avatar Aug 02 '22 12:08 SyrusBG

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

richeym-umich avatar Sep 12 '22 21:09 richeym-umich

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

garrettkajmowicz avatar Nov 06 '22 23:11 garrettkajmowicz

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

LOKESH-999 avatar Dec 30 '22 14:12 LOKESH-999

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.

ghost avatar Jan 20 '23 05:01 ghost

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.

richeym-umich avatar Jan 20 '23 14:01 richeym-umich

I don't have any idea But it's updated in python3.11

On Fri, 20 Jan, 2023, 7:57 pm richeym-umich, @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/heartexlabs/labelImg/issues/811#issuecomment-1398468302, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY6SOUW35W3IPHRHPCYPAYLWTKOFPANCNFSM5IIPE7CA . You are receiving this because you commented.Message ID: @.***>

LOKESH-999 avatar Jan 21 '23 17:01 LOKESH-999

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?

Michaelian624 avatar Aug 24 '23 06:08 Michaelian624

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()))

weiweijeff avatar Oct 20 '23 01:10 weiweijeff

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

clodoaldocodes avatar Jan 27 '24 13:01 clodoaldocodes