Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PYREX

1 view
Skip to first unread message

Burt Leavenworth

unread,
Jun 24, 2002, 12:34:57 PM6/24/02
to
Has anyone installed Pyrex on Windows? If so, can you share the
details?

Burt

Matthias Baas

unread,
Jun 24, 2002, 4:52:46 PM6/24/02
to

- Download Pyrex and Plex.
- Unpack Pyrex (you can use filzip (www.filzip.de), winzip
(www.winzip.com) or the cygwin tools (www.cygwin.com))
- Unpack Plex
- Copy the "Plex" directory into the Pyrex directory (the other files
aren't necessary for executing pyrex)

Now you can already call pyrexc, but probably you also want to add the
Pyrex directory to your path and rename "pyrexc" into "pyrexc.py".

If you want to use Plex yourself, it'd be better to install it as a
regular module, but if you just want to get pyrex running you can get
away with the above procedure.

- Matthias -

Darrell

unread,
Jun 25, 2002, 9:31:33 AM6/25/02
to
I've spent very little time with it. Just made it work and that's why
I love it. I use MSC 6 and the following setup.py, which I got from
Alex M. at the activestate python cookbook.

from distutils.core import setup, Extension
setup (name = "",
version = "1.0",
maintainer = "",
maintainer_email = "",
description = "Sample Python module",
ext_modules = [Extension('tcb',sources=['tcb.c','tcbBase.c'])]
)

#=======================
tcbBase.c has the detailed 'c' code and tcb.pyx has the interface.

cdef extern int openTcbC(int readTimeOut)
cdef extern int writeTcbC(char *cmdData, unsigned int cmdLen)
cdef extern char *readTcbC(unsigned int *bytesRead)
cdef extern PyString_FromStringAndSize(char *v, int len)
cdef extern int closeTcb()

def open(int readTimeOut):
return openTcbC(readTimeOut)

def write(data):
return writeTcbC(data, len(data))

def read():
cdef unsigned int bytesRead
cdef char *s
s=readTcbC(&bytesRead)
p=PyString_FromStringAndSize(s, bytesRead)
return p

def close():
closeTcb()

#==============================
This batch builds it all

python \python22\pyrexc.py tcb.pyx
setup.py build
copy C:\Python22\Lib\site-packages\Pyrex\Demos\build\lib.win32-2.2\*.pyd
.

#Yes I built in the demo directory :(

--Darrell

edl...@mindspring.com (Burt Leavenworth) wrote in message news:<3d1749d3...@news1.news.adelphia.net>...

Sandy Norton

unread,
Jul 13, 2002, 4:29:19 PM7/13/02
to
edl...@mindspring.com (Burt Leavenworth) wrote in message news:<3d1749d3...@news1.news.adelphia.net>...
> Has anyone installed Pyrex on Windows? If so, can you share the
> details?

Here's a dirty little script that allows me to type:

C:\> python pyx.py extension.pyx

and have pyrex produce an extension.c and an extension.pyd file
(assuming Pyrex is in sys.path of course). It's only been tested in
present form with single *.pyx files but I'm sure you can modify to do
what you want. Incidentally, I use Microsoft Visual C++ and winXP.

PS: Pyrex rocks.

ciao,

Sandy

<code>
# pyx.py
import sys, os, glob, time, shutil
import Pyrex.Compiler.Main


#GLOBAL
# variables
cwd = os.getcwd()
os.chdir(cwd)
timestamp = time.asctime(time.localtime())
filename = os.path.splitext(sys.argv[1])[0]
filenameExt = os.path.join(cwd, sys.argv[1])
# functions
join = os.path.join

# run pyrex compiler
Pyrex.Compiler.Main.main(c_only = 1, use_listing_file = 0)

def isMember(file):
x = len(filename)
if os.path.basename(file)[:x] == filename: return 1
else: return 0

# create setup.py for c files
setupfile = join(cwd, "setup.py")
files = glob.glob(join(cwd,"*.c"))
setup = open(setupfile, 'w')
setup.write("""# automatically generated - %s


from distutils.core import setup, Extension

setup(name = "%s", version = "1.0",
ext_modules = [Extension("%s", sources=%s)]
)
""" % (timestamp, filename, filename, [os.path.basename(file) for file
in files if isMember(file)]))
setup.close()

# compile corresponding python extension
os.system("python %s build" % setupfile)

# copy extension to python extension directory
path = join("build\\lib.win32-2.2", "*.pyd")
files = glob.glob(path)
for file in files:
shutil.copyfile(file, join(cwd, os.path.basename(file)))

# cleanup
shutil.rmtree(join(cwd, "build"))
os.remove('setup.py')
</code>

0 new messages