日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python3怎么使用pyrex_Win Python Pyrex 扩展

發(fā)布時(shí)間:2025/5/22 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3怎么使用pyrex_Win Python Pyrex 扩展 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在偶的ubuntu里編寫pyrex程序編譯成so還是挺爽的,用 timeit.Timer

測(cè)試性能提升不少,今天在windows也嘗試了一番。

需要的工具有:

-

Pyrexhttp://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/

- Dev C++http://www.bloodshed.net/devcpp.html

Pyrex 可以通過easy_install Pyrex來安裝。

Dev C++ 安裝完在系統(tǒng)環(huán)境變量Path里加上Dev C++安裝目錄/bin 目錄。

測(cè)試擴(kuò)展代碼:

# file: foo.pyx

""" simple pyrex module """

cdef class Foo:

""" foo doc ... """

cdef char *name

def __init__(self, name):

self.name = name

def __repr__(self):

return "foo names: %s" % (self.name)

# file: setup.py

from distutils.core import setup

from distutils.extension import Extension

from Pyrex.Distutils import build_ext

setup(

name='foo', ext_modules=[Extension("foo", ["foo.pyx"])],

cmdclass={'build_ext':build_ext}

)

寫好兩個(gè)文件后,進(jìn)入命令提示符:

C:\>python setup.py build_ext --inplace -c mingw32

running build_ext

pyrexc foo.pyx --> foo.c

building 'foo' extension

creating build

creating build\temp.win32-2.5

creating build\temp.win32-2.5\Release

C:\Program Files\DEV-CPP\Bin\gcc.exe -mno-cygwin -mdll -O -Wall -ID:\Python25\include -ID:\Python25\PC -c foo.c -o build\temp.win32-2.5\Release\foo.o writing build\temp.win32-2.5\Release\foo.def C:\Program Files\DEV-CPP\Bin\dllwrap.exe -mno-cygwin -mdll -static --entry _DllMain@12 --output-lib build\temp.win32-2.5\Release\libfoo.a --def build\temp.win32-2.5\Release\foo.def -s build\temp.win32-2.5\Release\foo.o -LD:\Python25\libs -L D:\Python25\PCBuild -lpython25 -lmsvcr71 -o foo.pyd

編譯完畢,可以看到當(dāng)前目錄下多了:build目錄、foo.c、foo.pyd。foo.pyd 即是編譯好的二進(jìn)制擴(kuò)展。

C:\>python

ActivePython 2.5.0.0 (ActiveState Software Inc.) based on

Python 2.5 (r25:51908, Mar 9 2007, 17:40:28) [MSC v.1310 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import foo

>>> foo.Foo("smallfish")

foo names: smallfish

? smallfish forsmallfish logs, 2009. |Permalink|No comment| Add

todel.icio.us

Post tags:Python

Feed enhanced byBetter FeedfromOzh

總結(jié)

以上是生活随笔為你收集整理的python3怎么使用pyrex_Win Python Pyrex 扩展的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。