views:

114

answers:

4

Virtualenv is great: it lets me keep a number of distinct Python installations so that different projects' dependencies aren't all thrown together into a common pile.

But if I want to install a package on Windows that's packaged as a .exe installer, how can I direct it to install into the virtualenv? For example, I have pycuda-0.94rc.win32-py2.6.exe. When I run it, it examines the registry, and finds only one Python26 to install into, the common one that my virtualenv is based off of.

How can I direct it to install into the virtualenv?

A: 

You can use environment's easy_install to install PyCUDA.

dev-env-path/bin/easy_install pycuda

it will give you the same version 0.94rc.

On Windows easy_install.exe will be in Scripts directory.

simplyharsh
Unfortunately, this will try to build from source. I was hoping to use pre-built binaries.
Ned Batchelder
A: 

If it's a .msi, you might be able to specify command line options using msiexec. The Python installer itself allows TARGETDIR, but I'm not sure if distutils bakes this into distribution installers.

If you're using a .exe, I don't think there's a clean way. One option is to use a program like 7Zip (or winzip, etc) to directly extract the contents of the exe, then copy the relevent folders into your virtual site-packages folder. For example, if I extract "processing-0.5.2.win32-py2.5.exe", I find a folder "PLATLIB\processing" which I copy to a virtualenv path and use without any runtime problems. (I'm not sure it's always that simple though.)

ars
+5  A: 

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.htm

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "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.

Ned Batchelder
A: 

easy_install is able to install .exe packages as long as they were built using distutils' bdist_wininst target, which covers many popular packages. However, there are many others that aren't (wxPython is one that I've struggled with)

Simon King
Yes, and as long as you've installed whatever development package of all the dependencies. In my case pycuda needs Boost and CUDA, not a trivial undertaking.
Ned Batchelder