How to build psycopg2.6 in Windows with VS2013
Building the psycopg2.6 in Python 2.7 has to use the VS2008 environment. Otherwise you will get an error message “Unable to find vcvarsall.bat”. But, now days, it’s hard to get VS2008 VC 9.0. If you have VS2013 already been installed, you can have a OS environment variable set as a simple workaround. For example, i have installed VS2013 in C:\app\VS12:
SET VS90COMNTOOLS=C:\app\VS12\Commons7\Tools\
The Python 2.7 psycopg2 setup script will look forward this environment variable and locate the vcvarsall.bat.
And then, the VC 12.0 has different headers and libraries from VC9.0. That will cause the error message showing below:
psycopgmodule.c
.\psycopg/config.h(134) : warning C4005: 'isnan' : macro redefinition
C:\app\VS12\VC\INCLUDE\math.h(289) : see previous definition of 'isnan'
.\psycopg/config.h(138) : warning C4005: 'isinf' : macro redefinition
C:\app\VS12\VC\INCLUDE\math.h(288) : see previous definition of 'isinf'
.\psycopg/config.h(150) : error C2491: 'round' : definition of dllimport function not allowed
error: Setup script exited with error: command 'C:\\app\\VS12\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2
To fix this one, you could apply this patch lines below to psycopg2.6\psycopg\config.h:
--- psycopg2-2.6/psycopg/config.h Mon Feb 9 18:00:36 2015
+++ psycopg2-2.6-1/psycopg/config.h Wed May 27 11:58:15 2015
@@ -130,19 +130,21 @@
#define inline
/* Hmmm, MSVC doesn't have a isnan/isinf function, but has _isnan function */
-#if defined (_MSC_VER)
+#if defined (_MSC_VER) && _MSC_VER < 1800
#define isnan(x) (_isnan(x))
/* The following line was hacked together from simliar code by Bjorn Reese
* in libxml2 code */
#define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) ? 1 \
: ((_fpclass(x) == _FPCLASS_NINF) ? -1 : 0))
-#define strcasecmp(x, y) lstrcmpi(x, y)
+
#endif
+
+#define strcasecmp(x, y) lstrcmpi(x, y)
#endif
#if (defined(__FreeBSD__) && __FreeBSD_version < 503000) \
- || (defined(_WIN32) && !defined(__GNUC__)) \
+ || (defined(_WIN32) && !defined(__GNUC__) && _MSC_VER < 1800) \
|| (defined(sun) || defined(__sun__)) \
&& (defined(__SunOS_5_8) || defined(__SunOS_5_9))
/* what's this, we have no round function either? */
Then, you could run the "easy_install .", you should be OK to build now.
However, this is not the whole story either a happy ending. When you start up the Python and import psycopg2 module, it will fail to load DLLs which psycopg2 depends on. These DLLs can be found in PostgreSQL Windows installation \bin folder. Copy the bin\lib*.dll, ssleay32.dll and zlib1.dll to your Python 2.7\\Lib\site-packages\psycopg2-2.6-py2.7-win-amd64.egg\psycopg2 folder. Now, you should be all set.