pyelftools ported to Python 3
January 27th, 2012 at 11:18 amI’ve released version 0.20 of pyelftools, with support for Python 3. Now pyelftools supports Python 2.6, 2.7 and 3.2 in a single code-base. The new version is also available on PyPI.
This was surprisingly painless for a project that has close to 6KLOC of Python code, probably because I planned for eventual Python 3 support from the start, and the minimal required version of Python 2 is 2.6, which is much more compatible with Python 3 than earlier versions in the 2.x line.
If you’re curious, here’s a direct link to the py3compat module which pyelftools uses for various compatibility issues between Python 2 and 3. It’s partially based on the six library.
By far the hardest part of this port to Python 3 was porting the construct library on which pyelftools relies for the low-level binary stream parsing. I’ve forked the construct Github repository to perform the port – it’s available here. After construct was ported, it took around 2 hours to port the rest of pyelftools. construct is also being distributed with pyelftools, so there are no actual external dependencies.
Related posts:

January 30th, 2012 at 16:40
Don’t forget to update your README to note that Python 3 is now supported. I’m not yet an hg users or I would send you a pull request myself
January 30th, 2012 at 19:25
Shawn,
Fixed, thanks for noticing.
October 23rd, 2012 at 18:00
Eli:
I’m learning (or attempting to learn) Python and one of my main uses will be to interface with RS232 ports. I came across you site and blog when I searched for Python serial ports.
I am running Python 3.2.3 and when I try to run you code from 2009 it bombs on me.
Here are the errors I get. Hope you have a quick fix suggestion.
Traceback (most recent call last):
File “C:\Python32\Simple Serial sender.py”, line 4, in
ser = serial.Serial(port, 38400)
File “C:\Python32\lib\site-packages\serial\serialwin32.py”, line 31, in __init__
SerialBase.__init__(self, *args, **kwargs)
File “C:\Python32\lib\site-packages\serial\serialutil.py”, line 261, in __init__
self.open()
File “C:\Python32\lib\site-packages\serial\serialwin32.py”, line 59, in open
raise SerialException(“could not open port %s: %s” % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port \\.\CNCB0: [Error 5] Access is denied.
Thanks.
Glenn.
October 24th, 2012 at 15:09
Hi Glenn,
You should really send this by email and not comment on an unrelated article. The script tries to open a virtual COM port created by com0com. You probably don’t have it unless you set it up, so you can use any physical COM port you may have (eg. COM1).