Issue #167 new

virtualenvwrapper_get_site_packages_dir is broken in Python 3.3 venv

Doug Latornell
created an issue

virtualenvwrapper_get_site_packages_dir() function fails in a directly created Python 3.3 venv.

This might be out of scope for virtualenvwrapper, so I won't complain if you close this issue as irrelevant.

If I create a virtualenv in my WORKON_HOME directory with:

$ pyvenv-3.3 test-3.3-venv

I can do all the usual virtualenvwrapper things with the exception of commands like lssitepackages that depend on virtualenvwrapper_get_site_packages_dir. They fail with:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sysconfig'
ls: fts_open: No such file or directory


(test-3.3-venv)$ python -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())'

works just fine, and that spelling also works in Python 2.7, 3,2, and 3.3 virtualenvs created via mkvirtualenv.

So, changing virtualenvwrapper_get_site_packages_dir to use:

import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())

would likely fix the issue without breaking backward compatibility.

I'm attracted to using pyvenv-3.3 in contrast to mkvirtualenv with Python 3.3 because the resulting virtualenv doesn't include all of symlinks in it's lib/ directory - cleaner.

Comments (4)

  1. Doug Hellmann repo owner

    Thanks for the detailed analysis, Doug. I will have to test that distutils change with earlier versions of python to see if it can be used directly, or if we need to do some version checking.

    I wonder if setting VIRTUALENVWRAPPER_VITUALENV to pyvenv-3.3 works with mkvirtualenv?

  2. Doug Latornell reporter
    $ VIRTUALENVWRAPPER_VIRTUALENV=pyvenv-3.3 mkvirtualenv test-3.3-venv

    does indeed create a Python 3.3 venv (i.e. no symlinks in lib/).

    Another interesting tidbit is that

    python -c "import distutils; print(distutils.sysconfig.get_python_lib())"

    doesn't work for me outside of a virtualenv! I'm on OS/X with framework installs of 2.7, 3.2, and 3.3 from the dmgs. That suggests that virtualenv is doing something to distutils in sys.modules, or something. And virtualenv not being involved when I use pyvenv-3.3 explains why I see the behaviour I do.

  3. John Purnell

    I have just come across this issue but in an Anaconda Python 3.3 environment which I installed into WORKON_HOME.

    To get it to work with virtualenvwrapper I had to rename their bin/activate and bin/deactivate scripts, then copy an existing virtualenv bin/activate (changing the VIRTUAL_ENV path) and bin/ into the Anaconda bin directory.

    Everything works fine except the virtualenvwrapper commands which use function virtualenvwrapper_get_site_packages_dir. If I change that to rather import distutils.sysconfig then they work as well. I have tested this change in the Anaconda environment as well as in virtualenvs created using OS X framework versions of Python 2.7.3, Python 3.2.5 and Python 3.3.2.

  4. Log in to comment