Sign in to follow this  
MrRage

PyRex

Recommended Posts

Hey there guys, I was wondering what you guys thought about PyRex. It looks really cool, only problem I’ve heard so far is that you need to use Visual Studio 7.1 to build the modules because Python was built with VC 7.1. A little bit of a problem for me because all I got is VC8. I went ahead and rebuilt Python with VC8 to see if that will solve the problem and so far the build I made seams to be working with other python modules. I don’t know how to build a PyRex module yet (or even a firm grasp on what’s needed to make one) but once I’m there I’ll give my newly built python exe a shot and see if that works. Added: Gezz... well that was a bust. I dug up my old copy of MSVC 7.1 academic and uninstalled MSVC 8 in prep to try again. I don't see why it won't work this time around. [Edited by - MrRage on July 12, 2007 8:26:34 AM]

Share this post


Link to post
Share on other sites
Crap.. now I have a DLL but havn't got a clue how to turn this into a module. The prime.dll is now in DLLs and I made an empty Libs/prime/__init__.py

So I'm missing something... perhaps I need to use disutils or something.

Share this post


Link to post
Share on other sites
Ok... Got it working with visual studio 7.1. Kind of a disappointment that I had to downgrade my compiler. But oh well, guess it really wasn't much of an upgrade if things stopped working.

For anyone hows interested in trying this out. Download Pyrex-0.9.x - install it using the setup .py.

1) Create a simple PyRex file, like so.

def primes(int kmax):
cdef int n, k, i
cdef int p[1000]
result = []
if kmax > 1000:
kmax = 1000
k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] <> 0:
i = i + 1
if i == k:
p[k] = n
k = k + 1
result.append(n)
n = n + 1
return result



2) Build that using the pyrexc script like so.
Quote:
python c:\Python25\Scripts\pyrexc.py prime.pyx


3) Build a project and compile the built code into a DLL. Key things - compile as C, DLL and I think thats it.

4) Use this setup.py to buld your new prime module.

from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
setup(
name = "prime",
ext_modules=[
Extension("prime", ["prime.pyx"], libraries = ["prime"])
],
cmdclass = {'build_ext': build_ext}
)




And finally - build the module using the command line:
Quote:
python setup.py build_ext --inplace


There you have it. This might be review for most of you but I burned my whole evening last night trying to figure this out on my own. So maybe now someone won't have to.

[Edited by - MrRage on July 12, 2007 11:59:34 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this