pyelftools ported to Python 3

January 27th, 2012 at 11:18 am

I’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:

  1. pyelftools – Python library for parsing ELF and DWARF
  2. Local execution of Python CGI scripts – with Python 3
  3. Automating boring testing activities with tox
  4. Python documentation annoyance
  5. Frames and protocols for the serial port – in Python

4 Responses to “pyelftools ported to Python 3”

  1. Shawn WheatleyNo Gravatar Says:

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

  2. elibenNo Gravatar Says:


    Fixed, thanks for noticing.

  3. Glenn TracyNo Gravatar Says:


    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”, line 4, in
    ser = serial.Serial(port, 38400)
    File “C:\Python32\lib\site-packages\serial\”, line 31, in __init__
    SerialBase.__init__(self, *args, **kwargs)
    File “C:\Python32\lib\site-packages\serial\”, line 261, in __init__
    File “C:\Python32\lib\site-packages\serial\”, 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.


  4. elibenNo Gravatar Says:

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

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)