admin's blog

Posted Thu 23 August 2012

Compiling Python Extensions in Windows Inside Virtualenv

If you are writing much Python code, there is a good chance you are using Virtualenv. If you are doing this under Windows, you may have had any number of problems (see previous rant).

My most recent issue came with trying to install Celery inside a virtualenv. My installation was failing when compiling the Billiard dependency with the following error:

C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\modules\_billiard\multiprocessing.o build\temp.win32-2.7\Re lease\modules\_billiard\semaphore.o build\temp.win32-2.7\Release\modules\_billiard\pipe_connection.o build\temp.win32-2. 7\Release\modules\_billiard\socket_connection.o build\temp.win32-2.7\Release\modules\_billiard\win32_functions.o build\t emp.win32-2.7\Release\modules\_billiard\_billiard.def -LC:\Users\aravenel\code\WeeklyMenus\venv\libs -LC:\Users\aravenel \code\WeeklyMenus\venv\PCbuild -lws2_32 -lpython27 -lmsvcr90 -o build\lib.win32-2.7\_billiard.pyd

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lpython27

collect2: ld returned 1 exit status

error: command 'gcc' failed with exit status 1

This as it turns out is an issue with the Virtualenv not correctly knowing the location of the Python libraries upon which it depends (notably libpython27.a). To fix this, simply edit the activate.bat script in your venv/Scripts folder to add the following line:

set LIBRARY_PATH=c:\python27\libs

Voila. No more compiler errors.

Answer found (as usual!) on StackOverflow

Category: Python
Tags: coding programming python virtualenv windows

Comments