[Pyrex] Using Visual C++
Lenard Lindstrom
len-l at telus.net
Mon Jan 12 20:47:55 CET 2009
Navid Parvini wrote:
> Dear All,
>
> I'm new in learning Pyrex, so I'm thankful for your help.
>
> I have written a code named first.pyx and then used "pyrex.py" to
> created "first.c" file but now I want to know how can I create
> "first.dll" file by using "Visual C++".
>
> Would you please help me?
>
> Thank you in advance.
>
> Regards,
> Navid
>
>
>
Hi Navid,
The easiest way to compile Pyrex extension modules is with Python's
distutils package, a part of the standard library. On Windows, Visual
C++ is used by default. To use distutils with Pyrex the Pyrex package
should be installed. To install Pyrex run:
python setup.py install
from Pyrex's distribution directory.
To build a project with distutils you need a setup.py file. I have
attached a simple example Pyrex module and it's setup file. To compile
and build the extension module do:
python setup.py build_ext --inplace
If all works well this should give you test.pyd, a Python extension
module DLL. Here is a quick Python session to confirm it worked:
>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', 'x']
>>> test.x()
This is it.
You can reuse the setup.py file by replacing "project = 'test'" with
"project = 'first'". The Python documents give a more thorough
explanation of setup.py and distutils in the top level document
"Distributing Python Modules". Pyrex specifics are given in the Pyrex
Language Overview under "Source Files and Compilation". Also:
python setup.py build_ext --help
will list command line options.
A further note, matching compilers with Python versions is a bit
involved on Windows. Python 2.3 used Visual C++ 6.0, Python's 2.4 and
2.5 use the 2003 toolkit, and Python 2.6 and 3.0 need Visual Studio
2008. Distutils refuses to compile a project if the wrong VC++ is installed.
Lenard
--
Lenard Lindstrom
<len-l at telus.net>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.pyx
Url: http://lists.copyleft.no/pipermail/pyrex/attachments/20090112/897a7f22/attachment.ksh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup.py
Type: application/x-python
Size: 277 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20090112/897a7f22/attachment.bin
More information about the Pyrex
mailing list