Building Pillow for PyPy - unresolved externals
Question: I've been struggling with building Pillow for PyPy (2.1) on my Windows (XP)
installation, using easy_install. Problems seems to be related to it missing
needed python/pypy header(?). I've been searching Google both up and down for
days, hoping to find a few who could elaborate on the problems I am having,
but not finding anything helpful.

The error log I am getting is:

    
    
    ...
    
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox
    /MD /W3 /GS- /DNDEBUG -IlibImaging -IC:\pypy-21\include -IC:\pypy-21\include /Tc
    libImaging\UnsharpMask.c /Fobuild\temp.win32-2.7\Release\libImaging\UnsharpMask.obj
    
    ...
    decode.obj : error LNK2001: unresolved external symbol __imp__PyType_Type
    encode.obj : error LNK2001: unresolved external symbol __imp__PyType_Type
    map.obj : error LNK2001: unresolved external symbol __imp__PyType_Type
    encode.obj : error LNK2019: unresolved external symbol __imp___PyString_Resize r
    eferenced in function __encode
    encode.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetFromErrno
     referenced in function __encode_to_file
    encode.obj : error LNK2019: unresolved external symbol __imp__PyExc_SystemError
    referenced in function __setimage
    display.obj : error LNK2019: unresolved external symbol __imp__PyList_Append ref
    erenced in function _list_windows_callback@8
    display.obj : error LNK2019: unresolved external symbol __imp__PyErr_Print refer
    enced in function _callback_error
    display.obj : error LNK2019: unresolved external symbol __imp__PyFile_WriteStrin
    g referenced in function _callback_error
    display.obj : error LNK2019: unresolved external symbol __imp__PySys_GetObject r
    eferenced in function _callback_error
    display.obj : error LNK2019: unresolved external symbol _PyObject_CallFunction r
    eferenced in function _windowCallback@16
    path.obj : error LNK2001: unresolved external symbol _PyObject_CallFunction
    display.obj : error LNK2019: unresolved external symbol __imp__PyThreadState_Swa
    p referenced in function _windowCallback@16
    display.obj : error LNK2019: unresolved external symbol __imp__PyThreadState_Get
     referenced in function _PyImaging_CreateWindowWin32
    path.obj : error LNK2019: unresolved external symbol __imp__PyErr_ExceptionMatch
    es referenced in function _PyPath_Flatten
    path.obj : error LNK2019: unresolved external symbol __imp__PyNumber_Check refer
    enced in function _PyPath_Flatten
    path.obj : error LNK2019: unresolved external symbol __imp__PyExc_RuntimeError r
    eferenced in function _path_clip_polygon
    build\lib.win32-2.7\_imaging.pypy-21.pyd : fatal error LNK1120: 61 unresolved ex
    ternals
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.e
    xe' failed with exit status 1120
    

I really struggle to see why this is happening, I actually have no clue. I am
easily able to build packages for CPython.

As far as I see dependencies folder is included as well:
"-IC:\pypy-21\include"(?).

For more of the log you can look at <http://pastebin.com/raw.php?i=kKnNpRgr>

**Edit - The solution**

After grabbing PyPy 2.2.1 I found that I was indeed missing some files in my
"PyPy-21/Include"-path. And so.. Pillow installed just fine with the newfound
header, and it's running flawlessly! =)


Answer: PyPy doesn't implement the entire C extension module API found in CPython. Or
rather, PyPy implements a reasonable subset of the symbols a Cext module is
most likely to use, but PyPY couldn't realistically provide every symbol
CPython provides without inhaling most of CPython. I wish CPython were more
careful about what symbols it exposes to external code, but I don't believe it
is.

PyPy is best with Pure Python modules. It can run (rather slowly) a subset of
C extension modules too. You may be fighting a losing battle trying to get
PyPy to import this particular CPython C extension module.

Bear in mind that you cannot JIT C code in PyPy.

