Compiling pyd II

Jason Orendorff jason at
Wed Jan 16 16:40:28 EST 2002

> As noted in a earlier post, I'm not certain about the compilation of pyd
> files.  I am aware that pyds are renamed dlls, though I'm unsure of the
> settings when compiling under MSVC.  In an attempt to compile _grabscreen
> ( the resulting dll was several times larger than the one
> supplied for a previous version of python.  More important is that python
> returns the error "module could not be found".  I could easily install the
> previous version of python but would like to understand what I'm doing
> wrong.

Well... the settings can be tricky.  Fortunately there is
an easy way to do this.

Save this code into a file named "" in the same directory
as "_grabscreen.c" and "".

# ------------------------------------------------------------
""" Setup script for grabscreen """
from distutils.core import setup, Extension

setup(name = "grabscreen",
      ext_modules = [Extension("_grabscreen",
                               sources = ["_grabscreen.c"],
                               libraries = ["gdi32"])],
      py_modules = ["ImageGrab"])
# ------------------------------------------------------------

Then do:
  python build
This builds everything, probably under .\build\lib.win32-2.2 .
On my computer, the resulting PYD file is 20K bytes.

If you decide to install it, you can:
  python install

## Jason Orendorff

More information about the Python-list mailing list