0

On Ubuntu 14.04 I run

mkvirtualenv -p /usr/bin/python3 myvenv

And I get

Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-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/dist-packages/virtualenv.py", line 39, in <module>
    import configparser as ConfigParser
  File "/usr/local/lib/python2.7/dist-packages/configparser.py", line 397
    _KEYCRE = re.compile(ur"%\(([^)]+)\)s")
                                         ^
SyntaxError: invalid syntax
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 15, in <module>
    from configparser import ConfigParser, NoOptionError, NoSectionError
  File "/usr/local/lib/python2.7/dist-packages/configparser.py", line 397
    _KEYCRE = re.compile(ur"%\(([^)]+)\)s")
                                         ^
SyntaxError: invalid syntax

Original exception was:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-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/dist-packages/virtualenv.py", line 39, in <module>
    import configparser as ConfigParser
  File "/usr/local/lib/python2.7/dist-packages/configparser.py", line 397
    _KEYCRE = re.compile(ur"%\(([^)]+)\)s")
                                         ^
SyntaxError: invalid syntax

It visibly is trying to install a python3 virtualenv using python2. How can I solve this?

e18r
  • 259
  • 8
  • 11

3 Answers3

2

I finally got it.

sudo pip uninstall virtualenv
sudo pip3 install virtualenv

That simple.

e18r
  • 259
  • 8
  • 11
1

The virtualenv.py should be compatible between python2.7 and python3.4.0. And yours is excepting because the python3 version cannot load the (renamed) ConfigParser module.

You seem to be running an older version of virtualenvwrapper. On my system virtualenv.py looks like:

try:
    import ConfigParser
except ImportError:
    import configparser as ConfigParser

around line 37 (virtualenvwrapper version 4.6.0), and that just falls back to using the new name configparser

You can try to upgrade using:

sudo pip install -U virtualenvwrapper

if you originally installed virtualenvwrapper with pip

Anthon
  • 277
1

This is so weird. I had solved this and I ran into this once more. My old suggestion wasn't enough.

This time I had to uninstall pip and pip3 and then reinstall them. I think my pip version was installed in a very weird fashion using easy_install, but I could uninstall it using:

sudo pip uninstall pip

Then I reinstalled pip:

sudo apt-get install python3-pip
e18r
  • 259
  • 8
  • 11