(guest@joequery.me)~ $ |

[SOLUTION] Tox error - undefined symbol: _PyErr_ReplaceException

Issue

I was using Tox to test python2.7. Python2.7 testing was executed via the "py27" environment. If I ran

$ tox -e py27

I received the following error traceback:

Traceback (most recent call last):
  File ".tox/py27/bin/pip", line 7, in <module>
    from pip import main
  File "/home/username/projects/argh/.tox/py27/lib/python2.7/site-packages/pip/__init__.py", line 13, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/username/projects/argh/.tox/py27/lib/python2.7/site-packages/pip/utils/__init__.py", line 15, in <module>
    import zipfile
  File "/usr/local/lib/python2.7/zipfile.py", line 6, in <module>
    import io
  File "/usr/local/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: /home/username/projects/argh/.tox/py27/lib/python2.7/lib-dynload/_io.so: undefined symbol: _PyErr_ReplaceException

Cause of the issue

This can happen if you upgrade your Python version corresponding to the tox test. In my case, I had upgraded python2.7 after tox had created its local copy within the .tox tox uses directory.

To verify this was the issue, I determined the version of python2.7 running on my system.

$ python2.7 --version

The response was

Python 2.7.10

But when I ran

$ .tox/py27/bin/python --version

The response was

Python 2.7.9

Solution

The easiest thing to do is just remove the .tox directory within your project and rebuild by rerunning the test for that environment.

$ rm -rf .tox

Be sure to also clear out the .pyc files that were generated by the old python version

$ find . -type f -name "*.pyc" -exec rm {} \;

Verification

$ .tox/py27/bin/python --version
Python 2.7.10

Woo!

Tagged as python, ubuntu

Date published - September 06, 2015