Pyrex installation on windows XP: step-by-step guide
Boris Borcic
bborcic at gmail.com
Wed Apr 26 10:53:53 EDT 2006
Julien Fiore wrote:
> Do you wand to install Pyrex on Windows ?
>
> Here is a step-by-step guide explaining:
>
> A) how to install Pyrex on Windows XP.
> B) how to compile a Pyrex module.
>
> Julien Fiore,
> U. of Geneva
Thanks. One detail missing : for this (step b3) to work smoothly, one needs to
make sure that (a copy of) eg python24.dll resides in Python24\libs\
>
> -------------------------------------------
>
> ### A) Pyrex installation on Windows XP ###
>
>
> # step A.1 #
> Install Python (we used version 2.4.2)
>
>
> # step A.2 #
> Run the windows installer for Pyrex (e.g. Pyrex-0.9.3.1.win32.exe),
> available on the Pyrex homepage
> (http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/)
>
>
> # step A.3 #
> Install Mingw, the gcc compiler for Windows, available at
> http://www.mingw.org/download.shtml. (we downloaded the file
> MinGW-5.0.2.exe and installed only the "base tool" (this includes
> mingw-runtime 3.9, w32api-3.6, binutils 2.15.91 and gcc-core 3.4.2).
> Add Mingw path ("C:\MinGW\bin") to the Windows "Path" environment
> variable. If you already have cygwin installed, add C:\MinGW\bin before
> the Cygwin path.
>
>
> # step A.4 #
> Create or edit the file "c:/Python2x/Lib/distutils/distutils.cfg" and
> put the following into it:
> [build]
> compiler = mingw32
>
> -------------------------------------------
>
>
> ### B) Create a Pyrex module ###
>
>
> # step B.1 #
> Create a working directory (e.g. D:\pyrex_module\). Write a pyrex
> module and save it with a "pyx" extension (e.g. "primes.pyx", code
> available on the Pyrex homepage)
>
>
> # step B.2 #
> Write the following python script and save it as "setup.py" in your
> working directory.
>
> from distutils.core import setup
> from distutils.extension import Extension
> from Pyrex.Distutils import build_ext
> setup(
> name = "PyrexGuide",
> ext_modules=[
> Extension("primes", ["primes.pyx"])
> ],
> cmdclass = {'build_ext': build_ext}
> )
>
> If you want to compile several modules, duplicate the line starting
> with "Extension" and replace "primes" by your module names.
>
>
> # step B.3 #
> In your working directory, create a batch file called
> "build_and_install.bat" containing the following lines, where
> "PythonXX" should be replaces by your Python version (e.g. "Python24").
>
> C:\Python24\python.exe setup.py build_ext install
> pause
>
> To run the batch, double-click the file. You will see many "Warning"
> messages during the building process: do not worry, it is normal.
>
>
> # step B.4 #
> Mission completed. The file "primes.pyd" (a "pyd" is a Python Extension
> DLL, equivalent of .so in Unix) is now located in
> "C:\Python24\Lib\site-packages" and the "primes" module is available in
> Python. In your working directory, you can delete the file "primes.c"
> and the "build" folder created by the building process.
>
> Test your new module at the python shell:
>
>>>> import primes
>>>> primes.primes(10)
> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>
> --------------------------------------------
>
More information about the Python-list
mailing list