Pages

Wednesday, 20 December 2017

使用Pypy



PyPy是一个独立的解析器, 通过即时编译(JIT,Just-in-time)代码避免逐行解释执行来提升运行速度的(将编译过的行代码缓存起来,从而加快速度)。我们一般使用的Python一般是使用C实现的,为了和其余解析器区分一般又叫CPython.

安装:

Win

直接官网下载安装就好了link

Mac安装:

brew install pypy
#brew install pypy

# Then appear:

# A "distutils.cfg" has been written to:
#   /usr/local/Cellar/pypy/2.6.1/libexec/lib-python/2.7/distutils
# specifying the install-scripts folder as:
#   /usr/local/share/pypy
# 
# If you install Python packages via "pypy setup.py install", easy_install_pypy,
# or pip_pypy, any provided scripts will go into the install-scripts folder
# above, so you may want to add it to your PATH *after* /usr/local/bin
# so you don't overwrite tools from CPython.
# 
# Setuptools and pip have been installed, so you can use easy_install_pypy and
# pip_pypy.
# To update setuptools and pip between pypy releases, run:
#     pip_pypy install --upgrade pip setuptools

安装外部库

由于pypy是独立的解析器,所以不能使用python中的外部库如numpy等.需要额外安装.
一般的库,使用pypy提供的相应版本工具easy_install_pypy,pip_pypy安装即可.
其中NumPy需要安装其提供的版本:
# 直接pip安装
pypy -m pip install git+https://bitbucket.org/pypy/numpy.git
# 或以下方式:
git clone https://bitbucket.org/pypy/numpy.git
cd numpy
pypy setup.py install
要使用numpy,官方还是建议使用numpy on CPython.

Reference

  1. Pypy
  2. Psyco-SF
  3. Python编程规范及性能优化(好文)
  4. Python性能优化的20条建议

No comments:

Post a Comment