Can I install Python windows packages into virtualenvs? Can I install Python windows packages into virtualenvs? windows windows

Can I install Python windows packages into virtualenvs?


Yes, you can. All you need is

easy_install binary_installer_built_with_distutils.exe

Surprised? It looks like binary installers for Windows made with distutils combine .exe with .zip into one .exe file. Change extension to .zip to see it's a valid zip file. I discovered this after reading answers to my question Where can I download binary eggs with psycopg2 for Windows?

UPDATE

As noted by Tritium21 in his answer nowadays you should use pip instead of easy_install. Pip can't install binary packages created by distutils but it can install binary packages in the new wheel format. You can convert from old format to the new one using wheel package, which you have to install first.


I know this is quite an old question, and predates the tools I am about to talk about, but for the sake of Google, I think it is a good idea to mention it. easy_install is the black sheep of python packaging. No one wants to admit using it with the new hotness of pip around. Also, while playing registry tricks will work best for non-standard EXE installers (someone built the installer themselves instead of using distutils, and is checking the registry for the installation path), there is now a Better Way(c) for standard EXE installers.

pip install wheelwheel convert INSTALLER.EXEpip install NEW_FILE_CREATED_IN_LAST_STEP.whl

The wheel format, introduced recently as of this post, is the replacement for the egg format, filling much the same role. This format is also supported by pip (a tool already installed in your virtualenv).

if for some reason pip install WHEELFILE does not work, try wheel install WHEELFILE


I ended up adapting a script (http://effbot.org/zone/python-register.htm) to register a Python installation in the registry. I can pick the Python to be the Python in the registry, run the Windows installer, then set the registry back:

# -*- encoding: utf-8 -*-## script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## Adapted by Ned Batchelder from a script# written by Joakim Löw for Secret Labs AB / PythonWare## source:# http://www.pythonware.com/products/works/articles/regpy20.htmimport sysfrom _winreg import *# tweak as necessaryversion = sys.version[:3]installpath = sys.prefixregpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)installkey = "InstallPath"pythonkey = "PythonPath"pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (    installpath, installpath, installpath)def RegisterPy():    try:        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)    except EnvironmentError:        try:            reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)        except Exception, e:            print "*** Unable to register: %s" % e            return    SetValue(reg, installkey, REG_SZ, installpath)    SetValue(reg, pythonkey, REG_SZ, pythonpath)    CloseKey(reg)    print "--- Python %s at %s is now registered!" % (version, installpath)if __name__ == "__main__":    RegisterPy()

Run this script with the Python you want to be registered, and it will be entered into the registry. Note that on Windows 7 and Vista, you'll need Administrator privileges.