Using Buildout system on Windows
Friday, April 22nd, 2011 11:30 am GMT +2
Okay, so you’ve heard something about buildout system, and started to use it. Once upon a time, your project is required to be deployed on Windows host. Let the show begin…
Buildout is extremely powerful, yet very simple to use tool to do automatic deployments. Imagine, that you need to deploy your app on some random unknown generic Linux host, where there is nothing but gcc and a few system tools (python included) — what a pain in the ass this could possibly be? Having to deal with manual installation of different packages (versions nightmare included) is such a pain. I don’t even want to consider what to do if you don’t have a root access rights on target machine.
Buildout is built by the Zope/Plone team to tackle all above mentioned problems. The only problem, though, is that it works smoothly only on *nix environments, which is not our case.
So, if there is absolutely no way around for you but deployment on Windows, read more.
Step 1. Prepare your windows environment
Scenario described below was tested on virtualboxed WindowsXP machine.
- Go to python.org and download Python 2.7.1, Run & install python into C:\Python27
- Go to Python Package Index (PyPI) and download setuptools-0.6c11.win32-py2.7.exe. Run & install. (If you have 64-bit windows system, go here http://www.lfd.uci.edu/~gohlke/pythonlibs/ and download setuptools-0.6c12dev.win-amd64-py2.7.exe)
- Go to PyWin32 page and download appropriate version for Python 2.7, run & install.
- Go to MinGW home page, download Windows installer, run mingw-get-inst.exe. Make sure to check “C++ compiler” during installation dialogs. By default, MinGW should be installed to C:\MinGW
- Install Unix utils for win32. Go to UnxUtils page, unzip all *.exe files to C:\Windows\system32, it is safe to overwrite some of existing system executables (Windows will complain about this, so you have to click OK in couple of dialogs)
Step 2. Set system %PATH% variable
It should include
- C:\Python27\
- C:\Python27\Scripts\
- C:\MinGW\bin\
Once, this is done gcc, python, easy_install commands should be available in your command line:
gcc:
C:\nimble\nimble-tests>gcc --v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++
--disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp
--disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs
--disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.2 (GCC)
easy_install:
C:\nimble\nimble-tests>easy_install --version
distribute 0.6.11
python:
C:\nimble\nimble-tests>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
chmod:
C:\nimble\nimble-tests>chmod --help
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL_MODE FILE...
-c, --changes like verbose but report only when a change is made
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
-R, --recursive change files and directories recursively
--help display this help and exit
--version output version information and exit
Each MODE is one or more of the letters ugoa, one of the symbols +-= and
one or more of the letters rwxXstugo.
Report bugs to fileutils-bugs@gnu.ai.mit.edu
Configure Distutils
Tell distutils to use MinGW
Create a file called ‘distutils.cfg’ in “C:\Python27\Lib\distutils”. Open it with a text editor (‘notepad distutils.cfg’) and fill in the following lines:
[build]
compiler = mingw32
This will allow to use buildout recipes which involve building C extensions.
Upgrade distutils to latest version
Make sure you have latest distutils version, otherwise your buildout will stuck in an infinite loop like this:
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Getting distribution for 'distribute'.
Fix this by upgrading distutils in your system-wide Python:
easy_install -U Distribute
Check out upgraded distutils version:
C:\nimble\nimble-tests>easy_install --version
distribute 0.6.15
Finally, run buildout
Run bootstrap:
python bootstrap.py
It will create bin directory & buildout.exe script, which we’re going to run. Here is an example output:
C:\nimble\nimble-tests\bin\buildout.exe
Develop: 'C:\\nimble\\nimble-tests\\src/se'
Uninstalling bin-templates.
Unused options for buildout: 'common-parts'.
Updating common-eggs.
Updating python.
Updating clean-bin-templates.
Installing bin-templates.
Other useful links
- http://eleddy.com/zopeskel_docs/buildoutwindows.html
- http://www.mingw.org/
- http://unxutils.sourceforge.net/
- http://sourceforge.net/projects/pywin32/
- http://collective-docs.plone.org/troubleshooting/buildout.html#getting-distribution-for-distribute