「Pystonを検証したいけど、ビルドとか嫌すぎる・・・」
「なんとかPythonの速度を改善したい」
このような人には、この記事を読んで欲しいです。
この記事を読めば、Pystonを気軽に検証できるようになります。
本記事の内容
- Pystonとは?
- Pystonのシステム要件
- Pystonのインストール
- Pystonの動作確認
それでは、上記に沿って解説していきます。
Pystonとは?
Pystonとは、Pythonを高速化したモノです。
Dropboxにより、オープンソースとして開発されています。
最新のPystonは、Python 3.8.8をベースにしています。
そして、PystonではPythonのコードをそのまま利用できます。
それでありながら、パフォーマンスが30%向上するということです。
状況によっては、さらにその数値は上昇すると言われています。
これが本当なら、使わない手はありません。
Pystonの開発者も「是非、使ってほしい」と述べています。
以上、Pystonに関する説明でした。
次は、Pystonのシステム要件を確認します。
Pystonのシステム要件
現時点(2021年8月)でのPystonの最新バージョンは、2.3となります。
この最新バージョンは、2021年7月17日にリリースされています。
サポートOSに関しては、以下を含むクロスプラットフォーム対応かどうかは不明です。
どこにも明示されていません。
- Windows
- macOS
- Linux
ソースが公開されている以上、ビルドできればどこでも動くはずです。
ただ、現状はLinux・macOSにインストールするのが無難でしょうね。
そして、ビルドするために必要なライブラリが以下。
- build-essential
- ninja-build
- git
- cmake
- clang
- libssl-dev
- libsqlite3-dev
- luajit
- python3.8
- zlib1g-dev
- virtualenv
- libjpeg-dev
- linux-tools-common
- linux-tools-generic
- linux-tools-`uname -r`(OS毎に異なる)
ビルドする場合は、インストールしておく必要があります。
ビルドでインストールする場合は、公式の手順通りにやってください。
なお、今回はビルドをしません。
よって、上記を事前にインストールする必要もありません。
debパッケージをインストールする方法を採用しています。
そして、OSはUbuntuに限定しています。
以上、Pystonのシステム要件の説明でした。
次は、Pystonをインストールしていきます。
Pystonのインストール
公式ダウンロードページ(GitHub)
https://github.com/pyston/pyston/releases
上記にアクセスします。
Pyston 2.3からdebパッケージが用意されています。

今回は、次のバージョンのUbuntuにインストールします。
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"
よって、「pyston_2.3_20.04.deb」を選択します。
URLを調べて、wgetでダウンロードします。
$ wget https://github.com/pyston/pyston/releases/download/v2.3/pyston_2.3_20.04.deb
ダウンロードしたdebパッケージをdpkg ユーティリティーでインストールします。
$ sudo dpkg -i pyston_2.3_20.04.deb
実行すると、以下のようにエラーが出ました。
$ sudo dpkg -i pyston_2.3_20.04.deb 以前に未選択のパッケージ pyston を選択しています。 (データベースを読み込んでいます ... 現在 94428 個のファイルとディレクトリがインストールされています。) pyston_2.3_20.04.deb を展開する準備をしています ... pyston (2.3) を展開しています... dpkg: 依存関係の問題により pyston の設定ができません: pyston は以下に依存 (depends) します: libtcl8.6 (>= 8.6.0) ...しかし: パッケージ libtcl8.6 はまだインストールされていません。 pyston は以下に依存 (depends) します: libtk8.6 (>= 8.6.0) ...しかし: パッケージ libtk8.6 はまだインストールされていません。 pyston は以下に依存 (depends) します: tk8.6-blt2.5 (>= 2.5.3) ...しかし: パッケージ tk8.6-blt2.5 はまだインストールされていません。 dpkg: パッケージ pyston の処理中にエラーが発生しました (--install): 依存関係の問題 - 設定を見送ります libc-bin (2.31-0ubuntu9.2) のトリガを処理しています ... 処理中にエラーが発生しました: pyston
足りないライブラリがあるようです。
それをインストールしてみます。
$ sudo apt-get update -y $ sudo apt-get install -y libtcl8.6
ここでも、エラーが出ました。
$ sudo apt-get install -y libtcl8.6
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
これらを直すためには 'apt --fix-broken install' を実行する必要があるかもしれません。
以下のパッケージには満たせない依存関係があります:
pyston : 依存: libtk8.6 (>= 8.6.0) しかし、インストールされようとしていません
依存: tk8.6-blt2.5 (>= 2.5.3) しかし、インストールされようとしていません
E: 未解決の依存関係です。'apt --fix-broken install' を実行してみてください (または解法を明示してください)。
ここは、指示通りに「apt –fix-broken install」を実行。
$ sudo apt --fix-broken install パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 依存関係を解決しています ... 完了 以下の追加パッケージがインストールされます: fontconfig-config fonts-dejavu-core libfontconfig1 libtcl8.6 libtk8.6 libxft2 libxrender1 libxss1 tk8.6-blt2.5 x11-common 提案パッケージ: tcl8.6 tk8.6 blt-demo 以下のパッケージが新たにインストールされます: fontconfig-config fonts-dejavu-core libfontconfig1 libtcl8.6 libtk8.6 libxft2 libxrender1 libxss1 tk8.6-blt2.5 x11-common アップグレード: 0 個、新規インストール: 10 個、削除: 0 個、保留: 0 個。 1 個のパッケージが完全にインストールまたは削除されていません。 3,460 kB のアーカイブを取得する必要があります。 この操作後に追加で 12.6 MB のディスク容量が消費されます。 続行しますか? [Y/n]
アップグレードがあれば、既存環境に影響を及ぼす可能性があります。
しかし、今回はすべて「新規インストール」となっています。
したがって、何も躊躇せずに「Y」をEnter。
処理が終わったら、再度debパッケージのインストールを実行します。
$ sudo dpkg -i pyston_2.3_20.04.deb (データベースを読み込んでいます ... 現在 98385 個のファイルとディレクトリがインストールされています。) pyston_2.3_20.04.deb を展開する準備をしています ... pyston (2.3) で (2.3 に) 上書き展開しています ... pyston (2.3) を設定しています ... libc-bin (2.31-0ubuntu9.2) のトリガを処理しています ...
無事に終了したようです。
以上、Pystonのインストールについて説明しました。
次は、Pystonの動作確認を行います。
Pystonの動作確認
pystonコマンドが利用できるようになっています。
pystonコマンドを用いて、動作確認を行います。
まずは、バージョン確認です。
$ pyston -V Python 3.8.8 (heads/2.3_release:4b9a88fc50, Jul 8 2021, 15:46:12) [Pyston 2.3.0, GCC 9.3.0]
Pystonのベースは、Python 3.8.8です。
そして、インストールしたのはPyston 2.3となります。
これらのことが、上記の結果で確認できます。
次は、ヘルプを確認しておきます。
$ pyston -h
usage: pyston [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-b : issue warnings about str(bytes_instance), str(bytearray_instance)
and comparing bytes/bytearray with str. (-bb: issue errors)
-B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O : remove assert and __debug__-dependent statements; add .opt-1 before
.pyc extension; also PYTHONOPTIMIZE=x
-OO : do -O changes and also discard docstrings; add .opt-2 before
.pyc extension
-q : don't print version and copyright messages on interactive startup
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S : don't imply 'import site' on initialization
-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x
-v : verbose (trace import statements); also PYTHONVERBOSE=x
can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
when given twice, print more information about the build
-W arg : warning control; arg is action:message:category:module:lineno
also PYTHONWARNINGS=arg
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt : set implementation-specific option. The following options are available:
-X faulthandler: enable faulthandler
-X showrefcount: output the total reference count and number of used
memory blocks when the program finishes or after each statement in the
interactive interpreter. This only works on debug builds
-X tracemalloc: start tracing Python memory allocations using the
tracemalloc module. By default, only the most recent frame is stored in a
traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a
traceback limit of NFRAME frames
-X showalloccount: output the total count of allocated objects for each
type when the program finishes. This only works when Python was built with
COUNT_ALLOCS defined
-X importtime: show how long each import takes. It shows module name,
cumulative time (including nested imports) and self time (excluding
nested imports). Note that its output may be broken in multi-threaded
application. Typical usage is python3 -X importtime -c 'import asyncio'
-X dev: enable CPython's "development mode", introducing additional runtime
checks which are too expensive to be enabled by default. Effect of the
developer mode:
* Add default warning filter, as -W default
* Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks() C function
* Enable the faulthandler module to dump the Python traceback on a crash
* Enable asyncio debug mode
* Set the dev_mode attribute of sys.flags to True
* io.IOBase destructor logs close() exceptions
-X utf8: enable UTF-8 mode for operating system interfaces, overriding the default
locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would
otherwise activate automatically)
-X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the
given directory instead of to the code tree
--check-hash-based-pycs always|default|never:
control how Python invalidates hash-based .pyc files
file : program read from script file
- : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH : ':'-separated list of directories prefixed to the
default module search path. The result is sys.path.
PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).
The default module search path uses <prefix>/lib/pythonX.X.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONUTF8: if set to 1, enable the UTF-8 mode.
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.
PYTHONHASHSEED: if this variable is set to 'random', a random value is used
to seed the hashes of str and bytes objects. It can also be set to an
integer in the range [0,4294967295] to get hash values with a
predictable seed.
PYTHONMALLOC: set the Python memory allocators and/or install debug hooks
on Python memory allocators. Use PYTHONMALLOC=debug to install debug
hooks.
PYTHONCOERCECLOCALE: if this variable is set to 0, it disables the locale
coercion behavior. Use PYTHONCOERCECLOCALE=warn to request display of
locale coercion and locale compatibility warnings on stderr.
PYTHONBREAKPOINT: if this variable is set to 0, it disables the default
debugger. It can be set to the callable of your debugger of choice.
PYTHONDEVMODE: enable the development mode.
PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.
最後は、Pythonスクリプトを実行しましょう。
次のコードを用意します。
実行しているPythonのバージョンを表示するプログラムです。
test.py
import sys print(sys.version)
test.pyを実行します。
実行は、pythonコマンドと同じ形式です。
pyston スクリプト名.py
実行した結果は、以下。
$ pyston test.py 3.8.8 (heads/2.3_release:4b9a88fc50, Jul 8 2021, 15:46:12) [Pyston 2.3.0, GCC 9.3.0]
「pyston -V」の実行結果と、全く同じ結果です。
何も難しくはありませんね。
以上、Pystonの動作確認を説明しました。

