Python3 virtualenv: ImportError: no module named ‘ConfigParser’

pippythonvirtualenv

I'm working on OSX and I'm trying to create a virtualenv with Python3, but I'm getting an error:

$ virtualenv --python python3 env
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 37, in <module>
    import ConfigParser
ImportError: No module named 'ConfigParser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 39, in <module>
    import configparser as ConfigParser
  File "/usr/local/lib/python2.7/site-packages/configparser.py", line 397
    _KEYCRE = re.compile(ur"%\(([^)]+)\)s")

It looks like it's looking for ConfigParser, which has been renamed configparser. Is that right? What can I do?

I've tried to update virtualenv with pip install -U virtualenvwrapper but it hasn't helped.

Best Answer

I had a similar issue, and I'm not certain if this will solve you problem, but for me it was due to a new version of python-future which jumped the queue in my path (ahead of the core python configparser) and then ran into issues.

What solved the problem for me was just removing the configparser.py file from that directory, since that wasn't the configparser that virtualenv is looking for.

To be fair, I think this issue was introduced in a more recent version of future (which is why I had a different error from you) but I imagine that given the path that your traceback is coming from, the issue still stems from it running into a configparser module that virtualenv doesn't expect to be there.

I'm filing an issue with the python-future folks, but other than that, I don't really know how to solve this issue other than to eliminate the version of configparser from its position on the path. Unfortunately, that also messes with future's ability to allow equivalence between import statements in python2 and python3.

Hope this helps!