-
So you wanna use Windows…
Those who know me are aware of the fondness I have for working with Windows in particular in the context of development. Whatever I think, however, many people choose, or are obliged, to develop on the platform. Depending on your chosen development tools, this can be more or less straight forward.
Consider this scenario: you’re a LAMP-stack developer (in this case, P is for Python). You’re going to be deploying to Linux in production and in test. You have mixed MacOS and Windows developers. The Mac (and Linux) guys have no trouble getting a dev environment built, but it can be a little trickier on Windows which is far less used by LAMP developers.
Windows peeps could change away from Windows but why should they add the switching cost of changing OS to all the rest? Clearly I think there are huge benefits, but I don’t usually like to tell people what to use, much as I myself don’t like being told what to use (yes, thank you, Eclipse is wonderful, but I’m really fast with Vi - I’ve worked with both).
So, how do we get some of the basics setup? Here are the steps I took.
Installing the basics: Python, setuptools, Git
Of course Git may not be a requirement for you as you may use SVN, Mercurial or something else. Git used to be considered ‘tricky’ on Windows, but that seems to be a thing of the past for general usage. The packages for all the above can be found at:
- Python: download the appropriate installer from the python.org website
- setuptools: download the appropriate installer from here; download the version appropriate to the Python version you installed (run
python --versionat the prompt to find out what that is if you need to) - Git: The MSYSgit package seems to be rather nice: obtain from here
- You may want to use tar in some scripts. If so, tar for windows can be obtained from here (after installation you’ll need to put the bin directory into your PATH; if you’ve taken the defaults you can add c:\Program Files\GnuWin32\bin)
Virtualenv is invaluable for many Python developers. Once setuptools is installed, virutalenv is straight forward:
C:\> easy_install virtualenvYou may find that you have to add
C:\python27\Scriptsto your path foreasy_installto be found.Now you can create virtual environments and pip install most things. If you don’t have Visual Studio or the C compiler, you’ll hit problems whenever an installation needs to compile components.
python-cjsonandhirediswill both be problematic, for example. Potential solutions involve installing the GNU C compiler or downloading unofficial binary builds of packages from helpful sources. These options will be explored at some time in the future if I find that I have to continue down this path.Installing Fabric
Fabric is the super-handy tool for managing remote servers and scripting operations to execute upon them. It can be easy installed but you’re likely to get the following error: GMP or MPIR library not found, followed “unable to find vcvarsall.bat” when
pycryptois installing. The solution is to install from a binary into the system packages. For this to work, your virtualenv must be configured to include system packages. The whole process is as follows- Download pycrypto from http://www.voidspace.org.uk/downloads/ - get the latest pycrypto for the version of Python you’re using (likely 2.7 at the time of writing)
- Install this for everyone on the system
- Create your virtualenv as
virtualenv --system-site-packages . - Now you can
pip install Fabric
Next problem: when you run
fabyou get told “No module named win32api”.To solve, install PyWin32 extensions:
- Download from http://sourceforge.net/projects/pywin32/files/pywin32/ the build appropriate to your Python version
- Run the executable
fab --listwill now work as expected.
Using gitpython
Now fabric is working you’re a good way in. I, however, am using fabric to deploy code from a Git commit. (note that it is very possible that life would be easier with Mercurial for this particular task on this particular platform…).
A few problems arise here. You are likely to encounter the message:
WindowsError: [Error 2] The system cannot find the file specified
To resolve, you will need to set an environment variable with the path to the git executable. If you’ve installed in the default location:
> set GIT_PYTHON_GIT_EXECUTABLE=”C:\Program Files\Git\bin\git.exe”
Though we’re not out of the woods yet… some operations may have issues. I’m getting access denied errors when a git archive is run via gitpython. This appears to be something to do with the subprocess and PIPE - my will to live is slowly being sapped so I may not make. Tell my family I love them…
… oh but I am still here! I admit, I quit. The Windows user I was trying to help is now deploying from a Linux box quickly spun up in EC2. So I’ve side-stepped the hassles above. Even if a work unfinished I hope that this may help some people. Should I need to solve any of these problems, and actually make progress, I’ll add to this page.
I should make clear that this page is a synthesis of tips and suggestions found across the web. I apologise for not properly crediting all my sources!