Python Forum
Error during 2to3 conversion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error during 2to3 conversion
#1
So I wanted to convert bk-chem-0.13.0 source code from Python 2 to Python 3 using 2to3. So in cmd, I ran this command so that it will convert all the files in the directory:

2to3 C:\User\Admin\Downloads\bkchem\. -w
So far, so good: here's some output dump sample from just before the error:

Output:
RefactoringTool: Refactored C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py --- C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py (original) +++ C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py (refactored) @@ -109,7 +109,7 @@ elif attr == 'hRes' or attr == 'vRes': # 16.16 fixed format, so just shift 16 bits self._stuff(attr, int(val) << 16) - elif attr in _pmElemFormat.keys(): + elif attr in list(_pmElemFormat.keys()): # any other pm attribute -- just stuff self._stuff(attr, val) else: @@ -129,7 +129,7 @@ elif attr == 'hRes' or attr == 'vRes': # 16.16 fixed format, so just shift 16 bits return self._unstuff(attr) >> 16 - elif attr in _pmElemFormat.keys(): + elif attr in list(_pmElemFormat.keys()): # any other pm attribute -- just unstuff return self._unstuff(attr) else: @@ -151,7 +151,7 @@ if y2 == None: dest[3] = y1 + src[3]-src[1] if not port: port = Qd.GetPort() - print "blit port:", port + print("blit port:", port) Qd.CopyBits(self.PixMap(), port.portBits, src, tuple(dest), QuickDraw.srcCopy, None)
And here, the error comes:

Error:
Traceback (most recent call last): File "c:\users\admin\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\admin\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\Scripts\2to3.exe\__main__.py", line 9, in <module> File "c:\users\admin\appdata\local\programs\python\python37\lib\site-packages\cmd_2to3\__main__.py", line 6, in main sys.exit(l2to3_main("lib2to3.fixes")) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\main.py", line 259, in main options.processes) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 687, in refactor items, write, doctests_only) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 280, in refactor self.refactor_dir(dir_or_file, write, doctests_only) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 300, in refactor_dir self.refactor_file(fullname, write, doctests_only) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 728, in refactor_file *args, **kwargs) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 322, in refactor_file input, encoding = self._read_python_source(filename) File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 318, in _read_python_source return f.read(), encoding File "c:\users\admin\appdata\local\programs\python\python37\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 18708: invalid start byte
Based on my understanding, I think that the error is not with the bkchem code (since there was no mention of it in the traceback), but with 2to3. What's happening and how to fix it?
Reply
#2
show code from line 322 (add lines before and after to show context)
Reply
#3
(Oct-14-2018, 01:32 AM)Larz60+ Wrote: show code from line 322 (add lines before and after to show context)

Code from codecs.py (lines 319-325):
def decode(self, input, final=False):
        # decode input (taking the buffer into account)
        data = self.buffer + input
        (result, consumed) = self._buffer_decode(data, self.errors, final)
        # keep undecoded input until the next call
        self.buffer = data[consumed:]
        return result
Reply
#4
I think you need encoding='windows-1252', but this apparently would be in self._buffer_decode()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Time conversion error tester_V 1 2,018 Oct-28-2020, 10:48 PM
Last Post: tester_V
  Data Type conversion error rajeevjagatap 2 4,333 Apr-15-2020, 03:29 PM
Last Post: rajeevjagatap
  python opencv grayscale conversion error Spandora 1 9,571 May-26-2019, 10:43 AM
Last Post: heiner55
  How to use 2to3.py converter under Windows OS samsonite 2 7,299 Mar-02-2019, 05:49 AM
Last Post: samsonite
  Confusing output from 2to3 about what files need change Moonwatcher 1 4,825 Dec-30-2018, 04:07 PM
Last Post: Gribouillis
  pyad time conversion error (plus solution) PapaZod 2 3,498 Nov-25-2018, 02:42 PM
Last Post: PapaZod
  Trying to convert a script from "2to3" JohnathanMonkey 15 10,131 Jul-31-2017, 08:05 PM
Last Post: Majora
  2to3 fails on very simple script Skaperen 21 17,234 Oct-20-2016, 08:23 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020