在Windows XP上安装Pyrex:分步指南 [英] Pyrex installation on windows XP: step-by-step guide

查看:93
本文介绍了在Windows XP上安装Pyrex:分步指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是否想在Windows上安装Pyrex?


这是一个循序渐进的指南解释:


A)如何在Windows XP上安装Pyrex。

B)如何编译Pyrex模块。


Julien Fiore,

U. of日内瓦


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


### A)在Windows XP上安装Pyrex ###

#step A.1#

安装Python(我们使用的是2.4.2版本)

#step A.2#

运行Pyrex的Windows安装程序(例如Pyrex-0.9.3.1.win32 Pyrex主页上提供$。b)b( http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

#step A.3#

安装Mingw,Windows的gcc编译器,可在
http://www.mingw.org/download.shtml 。 (我们下载了文件

MinGW-5.0.2.exe并仅安装了基础工具(这包括

mingw-runtime 3.9,w32api-3.6,binutils 2.15.91和gcc-core 3.4.2)。

将Mingw路径(C:\MinGW \ bin)添加到Windows路径环境中

变量。如果你已经安装了cygwin,请在

Cygwin路径之前添加C:\MinGW \ bin。

#step A.4#

创建或编辑文件c:/Python2x/Lib/distutils/distutils.cfg"并且

将以下内容添加到其中:

[build ]

编译器= mingw32


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

### B)创建Pyrex模块###

#step B.1 #

创建一个工作目录(例如D:\ pyrex_module \)。写一个pyrex

模块并用pyx保存它。扩展名(例如primes.pyx,代码

可在Pyrex主页上找到)

#步骤B.2#

写下列内容python脚本并将其另存为setup.py在你的

工作目录中。


来自distutils.core导入设置

来自distutils.extension import Extension

来自Pyrex.Distutils import build_ext

setup(

name =" PyrexGuide",

ext_modules = [

Extension(primes,[" primes.pyx"])

],

cmdclass = {''build_ext'':build_ext}




如果你想编译几个模块,请用Extension复制开始

的行。并取代素数按您的模块名称。

#步骤B.3#

在您的工作目录中,创建一个名为

" build_and_install.bat的批处理文件;包含以下行,其中

" PythonXX"应该用您的Python版本替换(例如Python24)。


C:\Python24 \ python.exe setup.py build_ext install

暂停


要运行批处理,请双击该文件。在构建过程中您会看到许多警告

消息:不用担心,这是正常的。

#步骤B.4#

任务完成。文件primes.pyd (pyd是一个Python扩展

DLL,相当于Unix中的.so)现在位于

" C:\Python24 \Lib \\ \\site-包"和素数模块可以在
Python中找到。在您的工作目录中,您可以删除文件primes.c

和build等。由构建过程创建的文件夹。


在python shell上测试你的新模块:

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)
import primes
primes.primes(10)



[2,3,5,7,11,13 ,17,19,23,29]


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


[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

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

推荐答案

Merci beaucoup!

非常感谢你!


-

@ -salutations


Michel Claveau
Merci beaucoup !
Thank you very much!

--
@-salutations

Michel Claveau


你能使用股票python构建还是你必须使用mingw从

scratch构建python来使用用mingw构建的pyrex模块?

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?


要安装Pyton,我只需使用python.org上的python Windows安装程序

(python-2.4.2.msi)。


Julien

To install Pyton, I simply used the python Windows installer
(python-2.4.2.msi) available at python.org.

Julien


这篇关于在Windows XP上安装Pyrex:分步指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆