Adding Python Twisted module to a virtualenv on Windows

I'm trying to keep my Python system-level install as clean as possible on Windows, but also trying to get Buildbot set up in a virtualenv. Unfortunately, some of the Buildbot dependencies want to build native extensions, and the most important --- Twisted --- just fails.

This is all I have in my system-level site-packages:

c:\>pip freeze
distribute==0.6.35
ipython==0.13.1
pyreadline==1.7.1
virtualenv==1.8.4

If I create a new virtualenv with --no-site-packages, then try to install the buildbot-slave package, I get the dreaded "Unable to find vcvarsall.bat" when Twisted is being installed:

copying twisted\test\raiser.c -> build\lib.win32-2.7\twisted\test
running build_ext
error: Unable to find vcvarsall.bat

Unfortunately, if you download and attempt to install the Twisted redistributable package from their website directly into a virtualenv, the installer package will register itself with the system, even if you select the "Install just for me" option. In other words, you can't just have the package install itself portably into multiple virtualenvs:

The User Account Control (UAC) dialog will pop up, and after the install, you'll be stuck with a single install of Twisted which can only be Repaired or Removed:

twisted-install-04

This situation kind of sucks. Unfortunately, the .exe version of the installer also won't let you choose where to install its contents. It just gets stuck on the dialog where it autodetects your existing Python 2.7 installation, but won't let you choose a different site-packages folder as a file destination. It only goes for the global install.

twisted-install-03

The solution is to download the .exe version of the installer, unpack it using something like 7-zip, and then copy the files from the PLATLIB folder to your virtualenv's Libs\site-packages and the the files from the SCRIPTS folder to your virtualenv's Scripts folder.

Then, the next time you run pip freeze, you should see something like:

(virtualenv) C:\virtualenv>pip freeze
Twisted==13.1.0

Then you can install the rest of the Buildbot packages:

(virtualenv) c:\virtualenv>pip install sqlalchemy==0.7.10
Downloading/unpacking sqlalchemy==0.7.10
  Downloading SQLAlchemy-0.7.10.tar.gz (3.5MB): 3.5MB downloaded
  Running setup.py egg_info for package sqlalchemy

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc\build\output'
Installing collected packages: sqlalchemy
  Running setup.py install for sqlalchemy
    building 'sqlalchemy.cprocessors' extension
    ***************************************************************************
    Unable to find vcvarsall.bat
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Failure information, if any, is above.
    Retrying the build without the C extension now.
    ***************************************************************************

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc\build\output'
    ***************************************************************************
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python build succeeded.
    ***************************************************************************
Successfully installed sqlalchemy
Cleaning up...

(virtualenv) c:\virtualenv>pip install buildbot-slave
Downloading/unpacking buildbot-slave
  Downloading buildbot-slave-0.8.8.zip (164kB): 164kB downloaded
  Running setup.py egg_info for package buildbot-slave

Requirement already satisfied (use --upgrade to upgrade): twisted>=8.0.0 in c:\virtualenv\lib\site-packages (from buildbot-slave)
Downloading/unpacking zope.interface>=3.6.0 (from twisted>=8.0.0->buildbot-slave)
  Downloading zope.interface-4.0.5.zip (173kB): 173kB downloaded
  Running setup.py egg_info for package zope.interface

    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\virtualenv\lib\site-packages\setuptools-0.6c11-py2.7.egg (from
 zope.interface>=3.6.0->twisted>=8.0.0->buildbot-slave)
Installing collected packages: buildbot-slave, zope.interface
  Running setup.py install for buildbot-slave

  Running setup.py install for zope.interface

    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    building 'zope.interface._zope_interface_coptimizations' extension
    ********************************************************************************
    WARNING:

            An optional code optimization (C extension) could not be compiled.

            Optimizations for this package will not be available!
    ()
    Unable to find vcvarsall.bat
    ********************************************************************************
    Skipping installation of c:\virtualenv\Lib\site-packages\zope\__init__.py (namespace package)
    Installing c:\virtualenv\Lib\site-packages\zope.interface-4.0.5-py2.7-nspkg.pth
Successfully installed buildbot-slave zope.interface
Cleaning up...

(virtualenv) c:\virtualenv>pip freeze
SQLAlchemy==0.7.10
Twisted==13.1.0
buildbot-slave==0.8.8
zope.interface==4.0.5