Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Pyrex installation on windows XP: step-by-step guide

Reply
Thread Tools

Pyrex installation on windows XP: step-by-step guide

 
 
Julien Fiore
Guest
Posts: n/a
 
      04-19-2006
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

-------------------------------------------

### 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]

--------------------------------------------

 
Reply With Quote
 
 
 
 
Michel Claveau
Guest
Posts: n/a
 
      04-19-2006
Merci beaucoup !
Thank you very much!

--
@-salutations

Michel Claveau


 
Reply With Quote
 
 
 
 
vj
Guest
Posts: n/a
 
      04-20-2006
Can you use the stock python build or do you have to build python from
scratch with mingw to use pyrex modules built with mingw?

 
Reply With Quote
 
Julien Fiore
Guest
Posts: n/a
 
      04-20-2006
To install Pyton, I simply used the python Windows installer
(python-2.4.2.msi) available at python.org.

Julien

 
Reply With Quote
 
Boris Borcic
Guest
Posts: n/a
 
      04-26-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]
>
> --------------------------------------------
>

 
Reply With Quote
 
sturlamolden
Guest
Posts: n/a
 
      04-26-2006

Julien Fiore wrote:
>
> # 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.



I don't think this is safe. MinGW links with msvcrt.dll whereas the
main Python distribution links with msvcr71.dll (due to Visual C++
2003). It is not safe to mix and blend different C runtime libraries.
If you are to build a C extension with MinGW, you also need to build
Python against msvcrt.dll, i.e. you have to use a Python built with
MinGW or Visual C++ 6.0. There other option is to make MinGW link
against msvcr71.dll. I don't know if that is feasible.

 
Reply With Quote
 
Julien Fiore
Guest
Posts: n/a
 
      04-27-2006
Thanks for your remark, Sturlamolden.

Is there a free version of the "Visual C++ 2003" compiler available on
the web? I have found "Visual C++ 2005 Express edition"
(http://msdn.microsoft.com/vstudio/express/visualc/). According to
Micrsoft, it replaces VC++2003
(http://msdn.microsoft.com/visualc/vctoolkit2003/). Is VC++2005ee the
good compiler to compile a Pyrex module (or any Python extension) ?
Does it link with msvcr71.dll ?

 
Reply With Quote
 
sturlamolden
Guest
Posts: n/a
 
      04-27-2006

Julien Fiore wrote:
> Thanks for your remark, Sturlamolden.
>
> Is there a free version of the "Visual C++ 2003" compiler available on
> the web? I have found "Visual C++ 2005 Express edition"
> (http://msdn.microsoft.com/vstudio/express/visualc/). According to
> Micrsoft, it replaces VC++2003
> (http://msdn.microsoft.com/visualc/vctoolkit2003/). Is VC++2005ee the
> good compiler to compile a Pyrex module (or any Python extension) ?
> Does it link with msvcr71.dll ?


The bad news is that "Visual C++ 2005 Express" links with msvcr80.dll,
which incompatible with both msvcrt.dll and msvcr71.dll. What you need
is the "Microsoft .NET Framework SDK Version 1.1". It contains version
7.1 of Microsoft's C/C++ compiler and links with the correct CRT.

http://tinyurl.com/5flob

I am not sure if this is an optimizing compiler. Microsoft did not give
away their optimizing compiler prior to "Visual C++ 2005 Express". Even
the standard version of Visual Studio did not have an optimizing
compiler, it only shipped with the professional and enterprise
versions. If this compiler does not optimize, you may try to make
"Visual C++ 2005 Express" use the import library for msvcr71.dll which
ships with the .NET SDK.

Now you know the meaning of the word "DLL HELL".

 
Reply With Quote
 
sturlamolden
Guest
Posts: n/a
 
      04-27-2006

sturlamolden wrote:

> I don't think this is safe. MinGW links with msvcrt.dll whereas the
> main Python distribution links with msvcr71.dll (due to Visual C++
> 2003).


In order to make minGW link with msvcr71.dll, edit the text file

c:\mingw\lib\gcc\mingw32\3.2.4\specs

and change "-lmsvcrt" to "-lmsvcr71".

Now MinGW will link with the same CRT as Python 2.4.

 
Reply With Quote
 
Julien Fiore
Guest
Posts: n/a
 
      04-28-2006
sturlamolden wrote:

> edit the text file "c:\mingw\lib\gcc\mingw32\3.2.4\specs"
> and change "-lmsvcrt" to "-lmsvcr71".


Thank you very much sturlamolden,

This procedure should be added to the "step-by-step" guide (see 1st
message of this thread) as "step A.5".

For ignorant people like me, CRT = "C runtime library".

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Pyrex installation on windows XP: step-by-step guide Fredrik Lundh Python 0 09-26-2007 08:53 AM
Step by step guide to convert AVI/MPEG/DivX/Mov/RMVB and many other videos to DVD bluesealover Computer Information 1 06-24-2007 09:52 PM
Step by step guide to convert AVI/MPEG/DivX/Mov/RMVB and many other videos to DVD bluesealover DVD Video 0 06-24-2007 08:51 PM
Step-by-Step Guide for Setting Up Secure Wireless Access in a Test Lab Mark Wireless Networking 0 03-24-2007 12:45 PM
Req. step by step guide of networking together win98se and winxppro. TIA roadster3043 Computer Support 5 10-22-2004 10:39 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57