Today I wanted to install the Python Cryptography Toolkit into a sandbox I had created using virtualenv. The issue was that the PCT was available as a Windows binary at The Voidspace Python Modules but I didn’t know how to install it to a sandbox because the EXE installer looks to the registry for the location of the system installation of Python.

After a little searching and experimenting I realized that all you need to do is to change the location the registry is point to from the system installation of Python to the sandboxed version.

So in my case I backed up the current registry key.

REGEDIT4
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
@="C:\\Python26\\"

And then created a copy of the file and modified it to point to the sandboxed Python install.

REGEDIT4
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
@="D:\\workspace\\mysandbox\\"

At this point you simply run the EXE installer and it will be installed to the sandbox. After it is installed, restore the original registry key.

update:

I am running 64-bit Windows 7 on one of my computers and see that the corresponding registry entry is at:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath
  • I used that info and the stdlib _winreg module to whip up a "virtualenv_install.py" script that temporarily replaces that key with the virtualenv one, calls subprocess.call() to launch a binary installer, then restores the original entry. Short and sweet. Thanks for the info!
blog comments powered by Disqus

Powered by Web Design Company Plugins