4

I've just forked a Python project that was built with test driven development. I certainly see its value and I'm looking forward to making further use out of it.

I've installed all the required Python interpreters (see tox.ini) using pyenv. Running tox -r, I end up with the following problem with 2.6 (I have other issues but those I can resolve):

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 20, in <module>
    import distutils.sysconfig
ImportError: No module named distutils.sysconfig

ERROR: InvocationError: /home/wxl/.pyenv/shims/python2.6 /usr/lib/python2.7/dist-packages/virtualenv.py --setuptools --python /home/wxl/.pyenv/shims/python2.6 py26 (see /home/wxl/dev/git/blogofobe/.tox/py26/log/py26-0.log)

Clearly not an issue with the code so much as attempting to invoke the virtualenv. The traceback seems to suggest it has something to do with missing modules, but those should be in the standard library, even in 2.6.

Interestingly, though if I run python2.6 and try to import distutils.sysconfig it fails. On the other hand, if I switch to that version with pyenv shell 2.6.9 and try the same thing, it works fine.

What am I missing?

FWIW, I'm on Ubuntu 14.04 and:

$ python --version
Python 2.7.6

$ python2.7 --version
Python 2.7.6

$ python2.6 --version
Python 2.6.9
wxl
  • 246
  • 3
  • 10

1 Answers1

3

It appears you're using the Debian-provided virtualenv with the python from the pyenv. This cannot work properly because Debian has patched site.py, distutils, sysconfig and probably the virtualenv you're trying to use to make certain assumptions about the file layout of the installed python. The dist-packages is a clear indicator of Debian-specific python patches.

These assumptions break with the standard python that pyenv installs. The solution is to install virtualenv inside the pyenv python, eg:

/home/wxl/.pyenv/shims/pip-2.6 install virtualenv

If you don't have the pip shim then use this:

/home/wxl/.pyenv/shims/easy_install-2.6 pip virtualenv

Don't forget to regenerate the shims by running pyenv rehash

ionelmc
  • 720
  • 2
  • 10
  • 29
  • 1
    i did at one point use the deadsnakes ppa to install some interpreters before i got irritated at it. looking at the version when running `python2.6` it's default whereas `pyenv shell 2.6.9` gives "unknown" so they're clearly different versions. `apt-get purge python2.6` resolved that issue. now all is well and `tox` is happy. thanks! – wxl Jan 22 '15 at 08:55
  • amazing - very helpful ty! – ledhed2222 Mar 24 '21 at 09:27