« ウインドウズ用のPythonモデュールのインストーラーがたくさんあるサイト | トップページ | 論文中のギリシャ文字など特殊文字のインサート »

2011年7月 7日 (木)

意外に簡単。Cythonのインストール・使い方覚書

CythonはPythonで書いた関数をCにコンパイルして、CエクステンションとしてPythonで利用できるというツール。コンパイルとかCエクステンションとか難しそうで敬遠していたが、やってみたら意外に簡単だ。極端な場合は100倍はやくなったりする。Pypyと違ってNumpyがすでにサポートされているし、PypyやShed Skinにくらべてほとんど使える関数に制限がないのが魅力。

(追記。Numpyをやり取りするCエクステンションのひな形も合わせて読むと吉かもしれません。)

ここを参考にインストール。Christoph Gohlkeさんのとこからバイナリインストーラーをもってくるのが一番速いけど、今回はなんとなく自分でビルドしてみた。

MinGWをインストール 最低gccとg++にチェック。
c:\mingw\binを環境変数Pathに追加。
distutilsがMinGWを使うように設定するため
[build]
compiler = mingw32
という内容でC\Python26\Lib\distutilにdistutils.cfgという名前で保存。
これでいちいちpython setup.py build --compiler==mingw32をする必要もなくなっていきなりpython setup.py installでよくなる。
Python26のところはバージョンに合わせて変えてください。

http://cython.org/release/から最新版を落とす。今回使ったのは0.14.1でした。

フツーに解凍してpython setup.py installでOK。pyximportが同梱されているのでpyxのC/C++へのコンパイルとCエクステンションの生成は自動化できる。

使い方はCythonでつくったモジュールをインポートするまえに
import pyximport
pyximport.install()
と書くだけでいい。コンパイルされたものは
C:\Users\ユーザー名\.pyxbld
のなかに出来ているはず。

うまくいかない場合、とくにXPではここにあるように
さらにpydistutils.cfgというファイルを
C:\Documents and Settings\ユーザー名\
につくってまたもや
[build]
compiler = mingw32
という内容で保存しないとだめだった。なぜかWindows 7だと必要なかったが。

完了!
テストしてみる。Robert Bradshawさんのスライドにある例をつかってみる。スライドのなかではcdef longとしていたが例にあるようにNが10の7乗とか大きいと振りきれるのでlong longにした。

def mysum(long N):
    cdef long long k,s = 0
    for k from 0 <= k < N:
        s += k
    return s

これをmycython.pyxという名前で保存。
これと同じフォルダーに

import pyximport
pyximport.install()
import mycython

N = 1e7
print mycython.mysum(N)

という内容でtest.pyとでもして記録、実行。一回目はコンパイルがはいる。
49999995000000
がでたら成功。

ちなみにすべてPythonで同じことをやるともちろん遅い。

def purepy_sum(N):
    s = 0
    for k in range(N):
        s += k
    return s

手元のパソコンでは、6-7秒かかったが、Cythonだと0.06秒で100倍早くなった。

« ウインドウズ用のPythonモデュールのインストーラーがたくさんあるサイト | トップページ | 論文中のギリシャ文字など特殊文字のインサート »

Python」カテゴリの記事

コメント

https://www.newjordansshoes.us.com/
https://www.pandorascharms.us.com/
https://www.jordans11.us.com/
https://www.goldengoosesales.us.com/
https://www.sneakersgoldengoose.us.com/
https://www.pandorasjewelry.us.com/
https://www.nike--shoes.us.com/
https://www.nikeoutletshoes.us.com/
https://www.nikeshoesforwomens.us.com/
https://www.jordan11ssneakers.us/
https://www.nikesales.us.com/
https://www.air-jordanssneakers.us/
https://www.nikeair-maxs.us.com/
https://www.monclerjacket.us.org/
https://www.ggdbshoes.us.com/
https://www.jordan-retro6.us/
https://www.jordan11low.us.com/
https://www.goldengoosemidstar.us.com/
https://www.retrosjordans.us/
https://www.jordans-4.us/
https://www.jordan-retro5.us/
https://www.air-jordan6.us/
https://www.nikesnkrs.us.com/
https://www.red-bottomsshoes.us.com/
https://www.jordan-12.us.com/
https://www.retro-jordans.us/
https://www.ggdbs.us.com/
https://www.jordan-4.us.com/
https://www.pandoraonline.us/
https://www.jordan13s.us/
http://www.pandorarings.us.com/
https://www.mensnikeshoes.us.com/
https://www.jordan11winlike96.us/
https://www.jordan10.us.com/
https://www.jordansneakerss.us/
https://www.yeezys-shoes.us.org/
https://www.jordanretros.us.com/
https://www.fitflop-shoes.us.org/
https://www.monclercom.us.com/
https://www.pandora-braceletcharms.us/
https://www.nike-airmax2018.us.com/
https://www.airjordansneakers.us.com/
https://www.new-jordans.us.com/
https://www.nikeairforce1.us.org/
https://www.ferragamos.us.org/
https://www.airmax-95.us.com/
https://www.nmds.us.com/
https://www.pandorajewellery.us.com/
https://www.jordansretro3.us/
https://www.jordan11red.us.com/
http://www.yeezys.com.co/
https://www.redbottomshoeslouboutin.us.com/
https://www.airforceoneshoes.us.com/
https://www.jamesharden-shoes.us.org/
https://www.airjordan5.us/
https://www.fjallraven-kanken.us.com/
https://www.jordan-8.us/
https://www.newjordan11.us/
https://www.pandoras.us.com/
https://www.goldengooseshoess.us.com/
https://www.jordanretro-11.us.com/
https://www.air-jordansneakers.us/
https://www.jordan1.us.com/
https://www.jordanshoess.us.com/
https://www.airjordanretro11.us.com/
https://www.redbottomslouboutin.us.org/
https://www.airmax270.us.org/
https://www.louboutinsshoes.us.com/
https://www.air-max90.us.com/
https://www.jordanscheapshoes.us/
https://www.huarachesnike.us.com/
https://www.monclerjacketsstore.us.com/
https://www.pandorajewelryofficialsite.us.com/
https://www.jordan-shoesformen.us.com/
https://www.nikeofficialwebsite.us.com/
https://www.valentinosshoes.us.org/
https://www.soccercleats.us.com/
https://www.airjordan3s.us/
https://www.goldensgoose.us.com/
https://www.airjordan11s.us.com/
https://www.jordans-sneakers.us.com/
https://www.monclerstoreoutlet.us.com/
https://www.yeezyonline.us.com/
https://www.outletgoldengoose.us.com/
https://www.air-jordans11.us.com/
https://www.air-jordan12.us/
https://www.ferragamo-outlets.us/
https://www.jordanretro11mens.us/
https://www.jordan9.us.com/
https://www.pandoracanadajewelry.ca/
https://www.airjordan6rings.us/
https://www.monclerstores.us.com/
https://www.retrosairjordan.us/
https://www.goldengoosesneakerss.us.com/
https://www.outletnikestore.us.com/
https://www.jameshardenshoes.com.co/
https://www.birkin-bag.us.com/
https://www.pandorasjewelry.ca/
https://www.fitflopsclearance.us.com/
https://www.shoeslouboutin.us.com/
https://www.jacketsmoncleroutlet.us.com/
https://www.kyrieirving-shoes.us.org/
https://www.nikesfactory.us.com/
https://www.nikeairmax98.us/
https://www.adidasyeezysshoes.us.com/
https://www.goldengoosessneakers.us.com/
https://www.yeezy.us.org/
https://www.yeezys-shoes.us.com/
https://www.canadapandoracharms.ca/
https://www.nikeshoesoutletfactory.us.com/
https://www.ggdbsneakers.us.com/
https://www.jordan12retros.us/
https://www.eccos.us.com/
https://www.balenciagas.us.org/
https://www.airjordan4s.us/
https://www.nikeairjordan.us.com/
https://www.jordan14.us.com/
https://www.shoes-jordan.us.com/
https://www.pandoraringssite.us/
https://www.nikesoutletstoreonlineshopping.us.com/
https://www.jordan11sshoes.us/
https://www.newnikeshoes.us.com/
https://www.nikeshoes-cheap.us.com/
https://www.jordans5.us/
https://www.balenciagatriples.us.org/
https://www.pandorajewelryofficial-site.us/
https://www.jordansretro12.us/
https://www.moncleroutletstoreonline.us.com/
https://www.jordans4retro.us/
https://www.monclervest.us.com/
https://www.jordans-11.us/
https://www.moncler-outletjackets.us.com/
https://www.goldengooseoutletfactory.us.com/
https://www.jordanshoesretro.us.com/
https://www.nikeoutletstoresonlineshopping.us.com/
https://www.adidasnmdr1.us.org/

https://www.pandorajewelry-officialsites.us/
https://www.pandoracharms-bracelets.us.com/
https://www.pandorajewelrysbracelets.us.com/
https://www.asicssneakers.us.com/
https://www.nikerunningshoessale.us.com/
https://www.pandorasjewelrys.us.com/
https://www.nikecanada-shoes.ca/
https://www.diorjordan1.us.com/
https://www.jordan1shoes.us.com/
https://www.pandoras-charms.us.com/
https://www.nikecom.ca/
https://www.pandorastores.us.com/
https://www.pandorascom.us.com/
https://www.nikecanadaonlineshopping.ca/
https://www.jordan1low.us.com/
https://www.airjordan1shoes.us.com/
https://www.pandoraoutletscharms.us.com/
https://www.pandorasjewelryoff.us.com/
https://www.jewelryspandora.us/
https://www.nikesnkrs.ca/
https://www.pandorajewelrysblackfriday.us.com/
https://www.wholesalejordanshoes.us/
https://www.pandorashop.us.com/
https://www.pandorass.us/
https://www.pandoracharmsstore.us.com/
https://www.adidasofficialwebsite.us.com/
https://www.yeezysshoes.ca/
https://www.jordan1retro.us.com/
https://www.balenciagashoess.us.com/
https://www.pandoraoutletjewelry.us.com/
https://www.adidassale.us.com/
https://www.adidasshoescheap.us.com/
https://www.wholesaleairjordanscheap.us/
https://www.pandoraringsjewelry.us.com/
https://www.pandorajewelrysofficialsite.us.com/
https://www.adidasnewshoes.us.com/
https://www.airjordan1low.us/
https://www.pandoracharmss.us.com/
https://www.adidasstoreoutlets.us.com/
https://www.ferragamosbelt.us.com/
https://www.adidasshoesfactory.us.com/
https://www.asicsgel-kayano.us.com/
https://www.adidascanadaonline.ca/
https://www.nikesstore.us.com/
https://www.monclersale.com.co/
https://www.pandora-outletcharms.us.com/
https://www.nikeshoesnew.us.com/
https://www.pandorabraceletsclearance.us.com/
https://www.adidas-runningshoes.us.com/
https://www.pandorasjewelrycharms.us.com/
https://www.asicsoutletshoes.us.com/
https://www.pandoraoutlet-online.us.com/
https://www.ferragamocom.us/
https://www.cheapjordanshoeswholesale.us/
https://www.monclercoat.com.co/
https://www.ferragamosbelts.us.com/
https://www.nikeoutletstore-onlineshopping.us.com/
https://www.nikesneakersformen.us.com/
https://www.outletasics.us.com/
https://www.goyardbagsoutlet.us.com/
https://www.pandorajewelrywebsites.us.com/
https://www.pandorasstore.us.com/
https://www.nikeshoes-formen.us.com/
https://www.nikescanadaonlineshopping.ca/
https://www.nikeoutletstoreonlineshopping.us.com/
https://www.salvatoreferragamos.us.com/
https://www.pandorajewelryoff.us.com/
https://www.airjordans1.us.com/
https://www.balenciagashoesstore.us.com/
https://www.pandoraoutletsonline.us.com/
https://www.pandorasjewelryofficialsite.us.com/
https://www.sneakersadidas.us.com/
https://www.pandorashops.us/
https://www.nikestorefactorys.us.com/
https://www.nikeairjordan1.us.com/
https://www.adidasshoeswomen.us.com/
https://www.trainersshop.uk.com/
https://www.airmax720.us.com/
https://www.pandorasofficialsite.us.com/
https://www.nikecanadaonlines.ca/
https://www.nikestoreoutlets.us.com/
https://www.pandora-jewellery.us.com/
https://www.monclerjacket.com.co/
https://www.pandoracharms-bracelets.us/
https://www.shoesferragamo.us.com/
https://www.yeezycanadashop.ca/
https://www.nikesneakersforwomen.us.com/
https://www.trainersforsale.uk.com/
https://www.airjordan1s.us.com/
https://www.adidass.ca/
https://www.nike--shoes.ca/
https://www.adidasshoesmen.us.com/
https://www.nikeoutlets.ca/
https://www.bestbasketballshoes.us/
https://www.asicsrunningshoess.us.com/
https://www.nikemensshoes.us.com/
https://www.cheapshoesoutletonlines.us/
https://www.balenciagasneakerssales.us.com/
https://www.pandora-charmssaleclearance.us/
https://www.pandoracharmsjewelrys.us/
https://www.nmd.us.com/
https://www.shoesasicsoutlet.us.com/
https://www.pandorasjewellery.us.com/
https://www.pandorabraceletsjewelry.us.com/
https://www.pandora-store.us.com/
https://www.nikeshoess.ca/
https://www.wholesalejordanshoes.us.org/
https://www.newshoes2021.us/
https://www.balenciagastore.us.com/
https://www.pandoraofficialsites.us.com/
https://www.jordanones.us/
https://www.jordan1high.us/
https://www.asicsshoess.us.com/
https://www.goyardhandbagsoutlet.us.com/
https://www.jordanretro1.us.com/
https://www.monclersjacketsoutlet.us.com/
https://www.balenciagasneakersoutlet.us.com/
https://www.nikeonline-canada.ca/
https://www.airjordan1retro.us.com/
https://www.pandorasoutlet.us.com/
https://www.pandora-jewelryoutlets.us.com/
https://www.pandorashops.us.com/
https://www.cheapmoncler.com.co/
https://www.pandorajewelrybracelets.us.com/
https://www.nikeshoes-forwomen.us.com/
https://www.outletsmonclerjackets.us.com/
https://www.monclersaleoutlets.us.com/
https://www.pandorasrings.us.com/
https://www.pandoras-outlet.us.com/
https://www.monclercoatsjacketsoutlet.us.com/
https://www.pandorasjewelry-officialsite.us.com/
https://www.pandoraoutletscharms.us/
https://www.yeezys350.ca/
https://www.monclersfactory.us.com/
https://www.balenciagatriplessneakers.us.com/
https://www.yeezycom.us/
https://www.pandorabraceletscharms.us.com/
https://www.pandorasjewelrysite.us.com/
https://www.outletstoreonlineshopping.com.co/
https://www.pandorasbraceletcharms.us.com/
https://www.charmspandoras.us/
https://www.pumashoess.us.com/
https://www.pandorajewelryshop.us.com/
https://www.nikeshoeswomen.us.com/
https://www.balenciagastores.us.com/
https://www.adidasshoes-canada.ca/

https://www.nbajerseyswholesalecheap.us.com/
https://www.nflfootballjerseysnew.us.com/
https://www.nflfanshop.us.com/
https://www.cheapnfljerseyswholesale.com.co/
https://www.hockeyjerseyscheap.us.com/
https://www.cheapnfljerseyswholesalefromchina.com.co/
https://www.nhlstore.com.co/
https://www.nflgearuniforms.us/
https://www.mlbbaseballjerseys.us.org/
https://www.wholesalecheapjerseysfromchina.us/
https://www.jerseyswholesalevip.us/
https://www.nbajerseysnew.us.com/
https://www.nflstores.com.co/
https://www.wholesalejerseys-cheap.us.com/
https://www.cheapnfljerseysfromchina.com.co/
https://www.officialnfljersey.us.com/
https://www.nbashop.us.org/
https://www.footballjerseysforcheap.us.com/
https://www.hockeyjerseyswholesale.us.com/
https://www.newfootballjerseys.us.com/
https://www.mlbshops.com.co/
https://www.nfljerseysofficialshop.us/
https://www.officialfootballjerseys.us.com/
https://www.mlbstore.us.org/
https://www.nbabasketballjerseyscheap.us.com/
https://www.wholesalenbajerseyscheap.us.com/
https://www.baseballjerseyssale.us.com/
https://www.cheapjerseysfromchinawholesale.com.co/
https://www.wholesalejerseyscheapest.us.com/
https://www.nflfootballjerseys.com.co/
https://www.nhljerseyscheapwholesale.us.com/
https://www.nflstoreonlineshopping.us/
https://www.cheapnbabasketballjerseys.us.org/
https://www.nflfanshop.com.co/
https://www.nflshop.com.co/
https://www.newnbajerseys.us.com/
https://www.cheapmlbjerseyswholesale.com.co/
https://www.nflshopofficial.org/
https://www.officialmlbstore.us.com/
https://www.mlbshops.us.org/
https://www.jerseyswholesaleforcheap.us.com/
https://www.wholesalenfljerseys.us.org/
https://www.cheapfootballjerseysfromchina.us.com/
https://www.cheapjerseyssale.us.org/
https://www.hockeyjerseyscheap.us/

https://www.retro-jordans.us/
https://www.airjordan6rings.us/
https://www.balenciagas.us.org/
https://www.jordan13s.us/
https://www.jordans-11.us/
https://www.ggdbs.us.com/
https://www.jordansneakerss.us/
https://www.monclerstores.us.com/
https://www.nike-airmax2018.us.com/
https://www.jordan11low.us.com/
https://www.ferragamo-outlets.us/
https://www.monclercom.us.com/
https://www.outletgoldengoose.us.com/
https://www.jordan1.us.com/
https://www.nikeairforce1.us.org/
https://www.sneakersgoldengoose.us.com/
https://www.birkin-bag.us.com/
https://www.jordan-12.us.com/
https://www.mensnikeshoes.us.com/
https://www.goldengoosesales.us.com/
https://www.jordanretro-11.us.com/
https://www.valentinosshoes.us.org/
https://www.jordansretro12.us/
https://www.newnikeshoes.us.com/
https://www.goldengoosemidstar.us.com/
https://www.pandorajewelryofficial-site.us/
https://www.nikeairmax98.us/
https://www.adidasnmdr1.us.org/
https://www.soccercleats.us.com/
https://www.airjordan11s.us.com/
https://www.monclerjacketsstore.us.com/
https://www.jordan11red.us.com/
https://www.jameshardenshoes.com.co/
https://www.huarachesnike.us.com/
https://www.nikeair-maxs.us.com/
https://www.airjordanretro11.us.com/
https://www.air-max90.us.com/
https://www.red-bottomsshoes.us.com/
https://www.jordansretro3.us/
https://www.pandoras.us.com/
https://www.air-jordan6.us/
https://www.nmds.us.com/
https://www.louboutinsshoes.us.com/
https://www.fitflop-shoes.us.org/
https://www.ggdbshoes.us.com/
https://www.pandoracanadajewelry.ca/
https://www.airjordan3s.us/
https://www.pandoraonline.us/
https://www.fjallraven-kanken.us.com/
https://www.yeezyonline.us.com/
https://www.monclervest.us.com/
https://www.nikesnkrs.us.com/
https://www.nikeshoesoutletfactory.us.com/
https://www.nikeoutletstoresonlineshopping.us.com/
https://www.goldengooseshoess.us.com/
https://www.nikesfactory.us.com/
https://www.pandorasjewelry.ca/
https://www.goldengoosessneakers.us.com/
https://www.retrosairjordan.us/
https://www.eccos.us.com/
https://www.yeezys-shoes.us.org/
https://www.jacketsmoncleroutlet.us.com/
https://www.jordan12retros.us/
https://www.jordanscheapshoes.us/
https://www.jordanshoesretro.us.com/
https://www.redbottomslouboutin.us.org/
https://www.moncler-outletjackets.us.com/
https://www.jordanretro11mens.us/
https://www.pandorasjewelry.us.com/
https://www.shoes-jordan.us.com/
https://www.fitflopsclearance.us.com/
https://www.airforceoneshoes.us.com/
https://www.jordan11sshoes.us/
https://www.jordan14.us.com/
https://www.newjordansshoes.us.com/
https://www.jordan11winlike96.us/
http://www.pandorarings.us.com/
https://www.jordanshoess.us.com/
https://www.jordans4retro.us/
https://www.jordans-sneakers.us.com/
https://www.monclerjacket.us.org/
https://www.jordan-retro5.us/
https://www.airjordan5.us/
https://www.kyrieirving-shoes.us.org/
https://www.ggdbsneakers.us.com/
https://www.redbottomshoeslouboutin.us.com/
https://www.retrosjordans.us/
https://www.pandoraringssite.us/
https://www.airmax270.us.org/
https://www.jamesharden-shoes.us.org/
https://www.jordan-4.us.com/
https://www.moncleroutletstoreonline.us.com/
https://www.nikeairjordan.us.com/
https://www.jordan11ssneakers.us/
https://www.jordan-shoesformen.us.com/
https://www.nikeoutletshoes.us.com/
https://www.yeezys-shoes.us.com/
https://www.airjordan4s.us/
https://www.pandora-braceletcharms.us/
https://www.air-jordansneakers.us/
https://www.jordan-retro6.us/
https://www.pandorascharms.us.com/
https://www.jordans-4.us/
https://www.balenciagatriples.us.org/
http://www.yeezys.com.co/
https://www.jordan-8.us/
https://www.shoeslouboutin.us.com/
https://www.jordans11.us.com/
https://www.air-jordan12.us/
https://www.nike--shoes.us.com/
https://www.ferragamos.us.org/
https://www.jordanretros.us.com/
https://www.newjordan11.us/
https://www.monclerstoreoutlet.us.com/
https://www.jordan10.us.com/
https://www.nikeshoes-cheap.us.com/
https://www.adidasyeezysshoes.us.com/
https://www.goldensgoose.us.com/
https://www.goldengooseoutletfactory.us.com/
https://www.nikeshoesforwomens.us.com/
https://www.jordans5.us/
https://www.canadapandoracharms.ca/
https://www.airjordansneakers.us.com/
https://www.air-jordans11.us.com/
https://www.nikesales.us.com/
https://www.air-jordanssneakers.us/
https://www.jordan9.us.com/
https://www.outletnikestore.us.com/
https://www.yeezy.us.org/
https://www.pandorajewelryofficialsite.us.com/
https://www.goldengoosesneakerss.us.com/
https://www.airmax-95.us.com/
https://www.nikeofficialwebsite.us.com/
https://www.nikesoutletstoreonlineshopping.us.com/
https://www.new-jordans.us.com/
https://www.pandorajewellery.us.com/

コメントを書く

(ウェブ上には掲載しません)

トラックバック


この記事へのトラックバック一覧です: 意外に簡単。Cythonのインストール・使い方覚書:

« ウインドウズ用のPythonモデュールのインストーラーがたくさんあるサイト | トップページ | 論文中のギリシャ文字など特殊文字のインサート »

しろののツイッタータイムライン(凍結中)

  • ツイッターは5つ目も凍結されました。6つ目での復活も不可能。なのでnoteに注力しています。

    と思ったら、イーロン・マスクの買収が公になってアカウントが復活できました。ありがとうマスク。

    トランプ関連記事の一覧リスト

オススメたち

2022年8月
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

はてブ

無料ブログはココログ