kcc icon indicating copy to clipboard operation
kcc copied to clipboard

Work-around to "RuntimeError... 'float' object cannot be interpreted as an integer during execution" for kcc-c2e.py powershell/CLI

Open aaronshiu opened this issue 3 years ago • 5 comments

Hope this is helpful, but I tried implementing the program running kcc-c2e.py for a directory/cbz archive file with powershell on windows. During execution, I kept coming across:

Processing images... Traceback (most recent call last): File "<Directory>\kcc\kcc-c2e.py", line 32, in startC2E() File "<Directory>\kcc\kindlecomicconverter\startup.py", line 49, in startC2E sys.exit(main(sys.argv[1:])) File "<Directory>\kcc\kindlecomicconverter\comic2ebook.py", line 74, in main makeBook(source) File "<Directory>\kcc\kindlecomicconverter\comic2ebook.py", line 1089, in makeBook imgDirectoryProcessing(os.path.join(path, "OEBPS", "Images")) File "<Directory>\kcc\kindlecomicconverter\comic2ebook.py", line 526, in imgDirectoryProcessing raise RuntimeError("One of workers crashed. Cause: " + workerOutput[0][0], workerOutput[0][1]) RuntimeError: ("One of workers crashed. Cause: 'float' object cannot be interpreted as an integer", ' File "<Directory>\kcc\kindlecomicconverter\comic2ebook.py", line 563, in imgFileProcessing\n img.autocontrastImage()\n File "<Directory>\kcc\kindlecomicconverter\image.py", line 258, in autocontrastImage\n self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255 * (a / 255.) ** gamma))\n File "C:\Program Files\Python310\lib\site-packages\PIL\Image.py", line 3107, in eval\n return image.point(args[0])\n File "C:\Program Files\Python310\lib\site-packages\PIL\Image.py", line 1680, in point\n return self._new(self.im.point(lut, mode))\n')

For kcc\kindlecomicconverter\image.py, on line 258, this was changed from: 255 * (a / 255.) ** gamma to: int(255 * (a / 255.) ** gamma)

So the line became: self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: int(255 * (a / 255.) ** gamma)))

This resolved the issue and allowed the program to run. :)

aaronshiu avatar Nov 30 '21 02:11 aaronshiu

Just tried this fix but all my pages are black? Does this occur for you too?

ScrambleTheRamble avatar Dec 03 '21 17:12 ScrambleTheRamble

Just tried this fix but all my pages are black? Does this occur for you too?

Hmm.. It seems alright for me when I open up converted files with Calibre e-book reader. It might have to do with how non-kindle programs display the black-white pages? Maybe you could ask the repo owner. :)

aaronshiu avatar Dec 05 '21 21:12 aaronshiu

I am having the same issue with Python 3.10. The last working version seems to be 3.9.9.

Maybe a pull request with the solution provided here can fix this issue? I don't know if there are better solutions though.

line 258 kcc/kindlecomicconverter/image.py

self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: int(255 * (a / 255.) ** gamma)))

A new minor release would be great too so it can be used via pip install on other projects. Currently a downgrade may be acceptable, but in the future may be a blocker to use some Python language features in version 3.10 and beyond.

Carleslc avatar Dec 23 '21 00:12 Carleslc

I am having the same issue with Python 3.10. The last working version seems to be 3.9.9.

Maybe a pull request with the solution provided here can fix this issue? I don't know if there are better solutions though.

line 258 kcc/kindlecomicconverter/image.py

self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: int(255 * (a / 255.) ** gamma)))

A new minor release would be great too so it can be used via pip install on other projects. Currently a downgrade may be acceptable, but in the future may be a blocker to use some Python language features in version 3.10 and beyond.

Thanks for it! At least the "path" is working for me.

koroki avatar Dec 25 '21 10:12 koroki

@aaronshiu The fix works with pillow 8.4.0, not with 8.3.2 (which is installed as an rpm on Fedora 35).

ScrambleTheRamble avatar Dec 30 '21 12:12 ScrambleTheRamble

  • fixed in #457

darodi avatar Jan 14 '23 19:01 darodi