========================== Frequently Asked Questions ========================== .. contents:: .. General ======= 一般的な話 ========== .. ------------- What is PyPy? ------------- ------------- PyPyとは何か ------------- .. PyPy is both: PyPyは次の両方を指します: .. - a reimplementation of Python in Python, and - PythonによるPythonの再実装 .. - a framework for implementing interpreters and virtual machines for programming languages, especially dynamic languages. - インタプリタを実装するフレームワークとプログラミング言語、特に動的言語の仮想マシン .. PyPy tries to find new answers about ease of creation, flexibility, maintainability and speed trade-offs for language implementations. For further details see our `goal and architecture document`_ . PyPyは作りやすさ、柔軟性、維持の容易さ、言語実装における速度のトレードオフに対する新しい解を見つけようとしています。 細かいことは `goal and architecture document`_ を参照してください。 .. _`goal and architecture document`: architecture.html .. _`drop in replacement`: .. ------------------------------------------ Is PyPy a drop in replacement for CPython? ------------------------------------------ ------------------------------- PyPyはCPythonの代わりになるの? ------------------------------- .. Almost! ほとんどできてます! .. The mostly likely stumbling block for any given project is support for `extension modules`_. PyPy supports a continually growing number of extension modules, but so far mostly only those found in the standard library. どんなプロジェクトでも十中八九つまずくところは拡張モジュールのサポートです。 PyPyは絶えず成長している多くの `extension modules`_ をサポートしていますが、 これまではたいてい標準ライブラリ内のものだけをサポートしてきました。 .. The language features (including builtin types and functions) are very complete and well tested, so if your project does not use many extension modules there is a good chance that it will work with PyPy. 言語の機能(組み込み型と組み込み関数を含む)は全くもって完全でテストも十分に行われていますので、 もしあなたのプロジェクトが多くの拡張モジュールを使っていなければ、 PyPyで上手く動作させるのにいい機会です。 .. We list the differences we know about in `cpython differences`_. 既知のCPythonとの違いを `cpython differences`_ に挙げました。 .. -------------------------------------------- Do CPython Extension modules work with PyPy? -------------------------------------------- ------------------------------------- CPython拡張モジュールはPyPyで動くの? ------------------------------------- .. We have experimental support for CPython extension modules, so they run with minor changes. This has been a part of PyPy since the 1.4 release, but support is still in beta phase. CPython extension modules in PyPy are often much slower than in CPython due to the need to emulate refcounting. It is often faster to take out your CPython extension and replace it with a pure python version that the JIT can see. CPython拡張モジュールの実験的サポートは行なっていますので、ちょっとコードを変えるだけで動きます。 この機能はPyPy 1.4から一部サポートしていますが、まだβ版です。 PyPyのCPython拡張モジュールは、参照カウントをエミュレートしなければいけないのでしばしばCPythonよりもずっと遅いです。 CPython拡張をpure python版に置き換えるとずっと速くなることもよくあります。 .. We fully support ctypes-based extensions. ctypesベースの拡張はすべてサポートしています。 .. For information on which third party extensions work (or do not work) with PyPy see the `compatibility wiki`_. PyPyでどの3rd party拡張が動くか(あるいは動かないか)については `compatibility wiki`_ を参考にしてください。 .. _`extension modules`: cpython_differences.html#extension-modules .. _`cpython differences`: cpython_differences.html .. _`compatibility wiki`: https://bitbucket.org/pypy/compatibility/wiki/Home .. --------------------------------- On which platforms does PyPy run? --------------------------------- ------------------------------------ PyPyはどのプラットフォームで動くか? ------------------------------------ .. PyPy is regularly and extensively tested on Linux machines and on Mac OS X and mostly works under Windows too (but is tested there less extensively). PyPy needs a CPython running on the target platform to bootstrap, as cross compilation is not really meant to work yet. At the moment you need CPython 2.5 - 2.7 for the translation process. PyPy's JIT requires an x86 or x86_64 CPU. PyPyは通常大規模にはLinuxとMac OS Xでテストされて、Windowsでもたいていは動作します。 (しかし前者2つよりはテストは小規模です)PyPyはブートストラップするために対象のプラットフォームでCPythonが動作している必要があり、 その理由でクロスコンパイルはまだ実際には動作していません。しばらくはCPython 2.5-2.7がトランスレーション処理に必要となります。 PyPyのJITはx86またはx86_64のCPUを必要とします。 .. ------------------------------------------------ Which Python version (2.x?) does PyPy implement? ------------------------------------------------ ----------------------------------------------------- PyPyはPythonのどのバージョン(2.x)を実装していますか? ----------------------------------------------------- .. PyPy currently aims to be fully compatible with Python 2.7. That means that it contains the standard library of Python 2.7 and that it supports 2.7 features (such as set comprehensions). PyPyは今のところPython 2.7と完全互換を目指しています。これはPython 2.7の標準ライブラリも含むという意味です。 そして2.7の機能(たとえばセット内包)もサポートします。 .. _threading: .. ------------------------------------------------- Does PyPy have a GIL? Why? ------------------------------------------------- --------------------------------------- PyPyにはGILがあるんですか?なぜですか? --------------------------------------- .. Yes, PyPy has a GIL. Removing the GIL is very hard. The first problem is that our garbage collectors are not re-entrant. はい、PyPyにはGILがあります。GILを取り除くのはとても厳しいです。 最初の課題はガベージコレクションがリエントリー性ではないということです。 .. ------------------------------------------ How do I write extension modules for PyPy? ------------------------------------------ -------------------------------------------------- PyPyの拡張モジュールはどうやって書けばいいですか? -------------------------------------------------- .. See `Writing extension modules for PyPy`__. `Writing extension modules for PyPy`__ を参照して下さい。 .. __: extending.html .. ----------------- How fast is PyPy? ----------------- ---------------------------- PyPyはどれくらい速いですか? ---------------------------- .. This really depends on your code. For pure Python algorithmic code, it is very fast. For more typical Python programs we generally are 3 times the speed of Cpython 2.6 . You might be interested in our `benchmarking site`_ and our `jit documentation`_. これはコードに依ります。pure Pythonのアルゴリズムコードならとても速いです。 典型的なPythonプログラムであれば、CPython 2.6の3倍速いです。 我々の `benchmarking site`_ と `jit documentation`_ も興味があればどうぞ。 .. _`benchmarking site`: http://speed.pypy.org .. _`jit documentation`: jit/index.html .. _`prolog and javascript`: .. -------------------------------------------------------------------------- Can I use PyPy's translation toolchain for other languages besides Python? -------------------------------------------------------------------------- ------------------------------------------------------------------------ PyPyのトランスレーションツールチェーンをPython以外の言語にも使えますか? ------------------------------------------------------------------------ .. Yes. The toolsuite that translates the PyPy interpreter is quite general and can be used to create optimized versions of interpreters for any language, not just Python. Of course, these interpreters can make use of the same features that PyPy brings to Python: translation to various languages, stackless features, garbage collection, implementation of various things like arbitrarily long integers, etc. はい、PyPyインタープリターを翻訳するツールスイートはかなり汎用的で、 Pythonだけでなく、どんな言語のインタープリタの最適化版を作るのにも使えます。 もちろん、これらのインタープリタはPyPyがPythonにもたらしたものと同じ機能を使うことができます。 具体的には様々な言語の翻訳機能、スタックレス、ガベージコレクション、任意長整数型などの様々実装などです。 .. Currently, we have preliminary versions of a JavaScript interpreter (Leonardo Santagada as his Summer of PyPy project), a `Prolog interpreter`_ (Carl Friedrich Bolz as his Bachelor thesis), and a `SmallTalk interpreter`_ (produced during a sprint). On the `PyPy bitbucket page`_ there is also a Scheme and an Io implementation; both of these are unfinished at the moment. 現在、JavaScriptインタープリタの暫定版を作っています。(Leonardo Santagadaが夏のPyPyプロジェクトでやっていました) `Prolog interpreter`_ の暫定版(Carl Friedrich Bolzの学士論文)や `SmallTalk interpreter`_ の暫定版(スプリント中に作られました)もあります。 `PyPy bitbucket page`_ にはSchemeとIoの実装もあります。どちらもいまはまだ完成していません。 .. _`Prolog interpreter`: https://bitbucket.org/cfbolz/pyrolog/ .. _`SmallTalk interpreter`: http://dx.doi.org/10.1007/978-3-540-89275-5_7 .. _`PyPy bitbucket page`: https://bitbucket.org/pypy/ .. Development =========== 開発 ==== .. ----------------------------------------------------------- How do I get into PyPy development? Can I come to sprints? ----------------------------------------------------------- ---------------------------------------------------------------------- PyPyの開発にはどのようにして関われますか?スプリントに参加できますか? ---------------------------------------------------------------------- .. Certainly you can come to sprints! We always welcome newcomers and try to help them as much as possible to get started with the project. We provide tutorials and pair them with experienced PyPy developers. Newcomers should have some Python experience and read some of the PyPy documentation before coming to a sprint. もちろんスプリントに参加できますよ!私たちはいつでも新人を歓迎していますし、 できるだけプロジェクトに参加しやすくなるようなお手伝いもしています。 チュートリアルや経験があるPyPy開発者とのペアプロも実施します。 スプリントに初めて参加する場合にはPythonの経験とPyPyのドキュメントを読んできて下さい。 .. Coming to a sprint is usually the best way to get into PyPy development. If you get stuck or need advice, `contact us`_. IRC is the most immediate way to get feedback (at least during some parts of the day; most PyPy developers are in Europe) and the `mailing list`_ is better for long discussions. スプリントに参加するのはPyPy開発をする上で最も良い方法です。 もし行き詰ってしまったりアドバイスが必要なら、私達に連絡して下さい( `contact us`_ )。 IRCは最も迅速にフィードバックを得られる方法です。 (少なくとも日中はそうです。ほとんどのPyPy開発者はヨーロッパにいます)そして `mailing list`_ は長い議論に向いています。 .. _`contact us`: index.html .. _`mailing list`: http://python.org/mailman/listinfo/pypy-dev .. ------------------------------------------------------------- OSError: ... cannot restore segment prot after reloc... Help? ------------------------------------------------------------- -------------------------------------------------------------- OSError: ...reloc後のセグメントprotを復元できません...ボスケテ -------------------------------------------------------------- .. On Linux, if SELinux is enabled, you may get errors along the lines of "OSError: externmod.so: cannot restore segment prot after reloc: Permission denied." This is caused by a slight abuse of the C compiler during configuration, and can be disabled by running the following command with root privileges:: Linux上ではSELinuxが有効になっていると、 “OSError: externmod.so: cannot restore segment prot after reloc: Permission denied.”に続くエラーが出てくると思います。 これはconfigure中のCコンパイラの乱用によるもので、次のコマンドをroot権限で実行すれば無効に出来ます:: # setenforce 0 .. This will disable SELinux's protection and allow PyPy to configure correctly. Be sure to enable it again if you need it! これでSELinuxの保護を無効にして、PyPyがきちんとconfigureされます。必要なときは再度有効にすることを忘れずに! .. The PyPy translation tool chain =============================== PyPyトランスレーションツールチェーン ==================================== .. --------------------------------------------- Can PyPy compile normal Python programs to C? --------------------------------------------- ------------------------------------------------------- PyPyは普通のPythonプログラムをCにコンパイルできますか? ------------------------------------------------------- .. No, PyPy is not a Python compiler. いいえ、PyPyはPythonのコンパイラではありません。 .. In Python, it is mostly impossible to *prove* anything about the types that a program will manipulate by doing a static analysis. It should be clear if you are familiar with Python, but if in doubt see [BRETT]_. Pythonでは、静的解析をすることでプログラムが扱う型を *証明する* ことはほぼ不可能です。 Pythonをよく知っていれば当たり前ですが、もし懐疑的なら [BRETT]_ を参考にしてください。 .. If you want a fast Python program, please use our JIT_ instead. もし速いPythonプログラムが欲しいなら、代わりに我々の JIT_ を使って下さい! .. _JIT: jit/index.html .. [BRETT] Brett Cannon, Localized Type Inference of Atomic Types in Python, http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.90.3231 .. _`PyPy's RPython`: .. ------------------------------ What is this RPython language? ------------------------------ ----------------------- RPythonとはなんですか? ----------------------- .. RPython is a restricted subset of the Python language. It is used for implementing dynamic language interpreters within the PyPy toolchain. The restrictions ensure that type inference (and so, ultimately, translation to other languages) of RPython programs is possible. RPythonとはPythonの制限されたサブセットです。これはPyPyツールチェーンの中で動的言語インタープリタを実装するのに使われます。 制限のお陰でRPythonプログラムの型推論が出来ます。(またそれによって究極的には他の言語へトランスレートできます) .. The property of "being RPython" always applies to a full program, not to single functions or modules (the translation toolchain does a full program analysis). The translation toolchain follows all calls recursively and discovers what belongs to the program and what does not. "RPythonになる"という特性は関数やモジュール1つではなく常にプログラム全てに適用されます。 (トランスレーションツールチェーンはプログラム全体の解析を行います)トランスレーションツールチェーンは全ての呼び出しを再帰的に追って、 何がどのプログラムに所属していて、何がそうでないかを見つけ出します。 .. RPython program restrictions mostly limit the ability to mix types in arbitrary ways. RPython does not allow the binding of two different types in the same variable. In this respect (and in some others) it feels a bit like Java. Other features not allowed in RPython are the use of special methods (``__xxx__``) except ``__init__`` and ``__del__``, and the use of reflection capabilities (e.g. ``__dict__``). RPythonプログラムは任意の方法での混合型の使用を制限します。RPythonは1つの変数に対して2つの異なる型を束縛することを許可しません。 この観点から(そしてほかの観点からも)Javaに似た感じがします。RPythonで許可されていない他の特徴としては、 ``__init__``, ``__del__`` 以外のスペシャルメソッド( ``__xxx__`` )の利用です。リフレクションも使えません。( ``__dict__`` など) .. You cannot use most existing standard library modules from RPython. The exceptions are some functions in ``os``, ``math`` and ``time`` that have native support. RPythonからはほとんどの標準ライブラリも使えません。例外はネイティブサポートがある ``os``, ``math``, ``time`` の一部の関数です。 .. To read more about the RPython limitations read the `RPython description`_. RPythonの制限についてもっと知りたい方は `RPython description`_ の説明を読んで下さい。 .. _`RPython description`: coding-guide.html#restricted-python .. --------------------------------------------------------------- Does RPython have anything to do with Zope's Restricted Python? --------------------------------------------------------------- -------------------------------------------------- RPythonはZopeのRestricted Pythonと関係ありますか? -------------------------------------------------- .. No. `Zope's RestrictedPython`_ aims to provide a sandboxed execution environment for CPython. `PyPy's RPython`_ is the implementation language for dynamic language interpreters. However, PyPy also provides a robust `sandboxed Python Interpreter`_. いいえ、 `Zope's RestrictedPython`_ はCPythonのサンドボックス実行環境を提供しようとしているものです。 `PyPy's RPython`_ は動的言語インタープリタを実装するための言語です。 しかしながらPyPyはロバストな `sandboxed Python Interpreter`_ も提供しています。 .. _`sandboxed Python Interpreter`: sandbox.html .. _`Zope's RestrictedPython`: http://pypi.python.org/pypi/RestrictedPython .. ------------------------------------------------------ What's the ``"NOT_RPYTHON"`` I see in some docstrings? ------------------------------------------------------ -------------------------------------------------- Docstringにある ``"NOT_RPYTHON"`` とはなんですか? -------------------------------------------------- .. If you put "NOT_RPYTHON" into the docstring of a function and that function is found while trying to translate an RPython program, the translation process stops and reports this as an error. You can therefore mark functions as "NOT_RPYTHON" to make sure that they are never analyzed. "NOT_RPYTHON"と関数のdocstringに書けば、その関数はRPythonプログラムのトランスレート中に見つけられ、 トランスレート処理が止まってエラーとして報告します。 それ故、関数を"NOT_RPYTHON"とマークすることでそれらを絶対に解析されないように出来ます。 .. ------------------------------------------------------------------- Couldn't we simply take a Python syntax tree and turn it into Lisp? ------------------------------------------------------------------- ---------------------------------------------------------- Pythonの構文木を単純にLispに変換することはできないですか? ---------------------------------------------------------- .. It's not necessarily nonsense, but it's not really The PyPy Way. It's pretty hard, without some kind of type inference, to translate this Python:: 必要無いですしナンセンスですし、PyPyのやり方ではありません。このPythonをトランスレートするのはなんらかの型推論なしにはとても難しいです:: a + b .. into anything significantly more efficient than this Common Lisp:: これを次のCommonLispよりも意味があるものにするのは難しいです:: (py:add a b) .. And making type inference possible is what RPython is all about. そして型推論を可能にするのがRPythonがしていることです。 .. You could make ``#'py:add`` a generic function and see if a given CLOS implementation is fast enough to give a useful speed (but I think the coercion rules would probably drive you insane first). -- mwh ``#'py:add`` を汎用関数にして、CLOS実装が実用的な速度で動くか確かめてもいいでしょう。 (しかし私が思うにその矯正ルールはまずあなたを狂わせるでしょう)―mwh .. -------------------------------------------- Do I have to rewrite my programs in RPython? -------------------------------------------- ----------------------------------------------------------- 私のプログラムをRPythonに書き換えなければいけないのですか? ----------------------------------------------------------- .. No. And you shouldn't try. PyPy always runs your code in its own interpreter, which is a full and compliant Python 2.7 interpreter. RPython is only the language in which parts of PyPy itself are written and extension modules for it. Not only is it not necessary for you to rewrite your code in RPython, it probably won't give you any speed improvements if you try. いいえ。そして試すことすらすべきではありません。PyPyは常に独自のインタープリタでコードを走らせます。 インタープリタはPython 2.7に完全準拠しています。RPythonはPyPy自身とそれ用の拡張モジュールが一部書かれている言語にすぎません。 RPythonでコードを書き直す必要がないだけでなく、試してみても速度の改善には繋がらないと思います。 .. --------------------------------------------------- Which backends are there for the RPython toolchain? --------------------------------------------------- ----------------------------------------------------------- RPythonのツールチェーンにはどんなバックエンドがありますか? ----------------------------------------------------------- .. Currently, there are backends for C_, the CLI_, and the JVM_. All of these can translate the entire PyPy interpreter. To learn more about backends take a look at the `translation document`_. 現在のところ、 C_ 、 CLI_ 、 JVM_ のバックエンドがあります。これらすべてPyPyインタープリタ全体をトランスレート可能です。 バックエンドについてもっと知りたい方は `translation document`_ を見てください。 .. _C: translation.html#the-c-back-end .. _CLI: cli-backend.html .. _JVM: translation.html#genjvm .. _`translation document`: translation.html .. ---------------------- How do I compile PyPy? ---------------------- ---------------------------------------- どのようにPyPyをコンパイルするのですか? ---------------------------------------- .. See the `getting-started`_ guide. `getting-started`_ のガイドを読んで下さい。 .. _`getting-started`: getting-started-python.html .. _`how do I compile my own interpreters`: .. ------------------------------------- How do I compile my own interpreters? ------------------------------------- ---------------------------------------------------------- どのようにオレオレインタープリタをコンパイルするのですか? ---------------------------------------------------------- .. Begin by reading `Andrew Brown's tutorial`_ . `Andrew Brown's tutorial`_ を読むことから始めて下さい。 .. _`Andrew Brown's tutorial`: http://morepypy.blogspot.com/2011/04/tutorial-writing-interpreter-with-pypy.html .. --------------------------------------------------------- Can RPython modules for PyPy be translated independently? --------------------------------------------------------- --------------------------------------------------------------- PyPy向けのRPythonモジュールは独立してトランスレートできますか? --------------------------------------------------------------- .. No, you have to rebuild the entire interpreter. This means two things: いいえ、インタープリタ全体を再ビルドする必要があります。理由は次の2つです: .. * It is imperative to use test-driven development. You have to test exhaustively your module in pure Python, before even attempting to translate it. Once you translate it, you should have only a few typing issues left to fix, but otherwise the result should work out of the box. * テスト駆動開発をする義務があります。 トランスレートする前にさえ、あなたのモジュールをpure Pythonで徹底的にテストしなければなりません。 一度トランスレートしたら、直すのはいくつかの型の問題だけになるでしょう。そうでなければそのまま動作します。 .. * Second, and perhaps most important: do you have a really good reason for writing the module in RPython in the first place? Nowadays you should really look at alternatives, like writing it in pure Python, using ctypes if it needs to call C code. Other alternatives are being developed too (as of summer 2011), like a Cython binding. * 次が最も大事です:まずRPythonでモジュールを書くのに真っ当な理由がありますか? 近頃では代替の方法を見るべきで、たとえばCのコードを呼ぶ必要があるならpure Pythonでctypesを使ってみるなどです。 他の方法としては(2011年夏の段階では)Cythonバインディングのようなものも開発されています。 .. In this context it is not that important to be able to translate RPython modules independently of translating the complete interpreter. (It could be done given enough efforts, but it's a really serious undertaking. Consider it as quite unlikely for now.) このような理由から、RPythonモジュールをインタープリタ全体のトランスレートとは独立してトランスレートできることはさほど重要ではありません。 (かなり頑張ればできないことはないですが、それは大仕事です。いまは見込みがないと思ったほうがいいです) .. ---------------------------------------------------------- Why does PyPy draw a Mandelbrot fractal while translating? ---------------------------------------------------------- ---------------------------------------------------------------------- なぜPyPyはトランスレーションの間Mandelbrotのフラクタルを描くんですか? ---------------------------------------------------------------------- .. Because it's fun. 楽しいからです。 .. include:: _ref.txt