如何在Mac上使用PyPy?

时间:2013-12-10 18:30:59

标签: python pypy

PyPy的速度承诺让我想尝试一下。不幸的是,我在这个主题上阅读的教程都没有真正帮助我理解基础知识,即如何(简单的步骤):

  • 在Mac上安装PyPy
  • 运行.py脚本

我读到从pypy myscript.py下载,提取和运行bin/应该可以解决这个问题,但到目前为止我没有运气。这是我得到的:

MyMacbook:bin User$ pypy myscript.py
-bash: pypy: command not found

有人能帮我理解PyPy的基本用法吗?

1 个答案:

答案 0 :(得分:9)

您是否尝试过使用自制程序(http://brew.sh/)?

~ $ brew search pypy
pypy

看起来像“brew install pypy”应该可以帮助你。

~ $ brew versions pypy
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
https://github.com/Homebrew/homebrew-versions
2.2.0    git checkout 4d471b1 /usr/local/Library/Formula/pypy.rb
2.1.0    git checkout ff5dd19 /usr/local/Library/Formula/pypy.rb
2.0.2    git checkout 58b36e9 /usr/local/Library/Formula/pypy.rb
2.0.1    git checkout 82b72d3 /usr/local/Library/Formula/pypy.rb
2.0      git checkout 280581d /usr/local/Library/Formula/pypy.rb
1.9      git checkout 28557b8 /usr/local/Library/Formula/pypy.rb
1.8      git checkout 93bda7d /usr/local/Library/Formula/pypy.rb
1.7      git checkout eee60ad /usr/local/Library/Formula/pypy.rb
1.6.0    git checkout b9b1f35 /usr/local/Library/Formula/pypy.rb
1.5.0    git checkout d0c75a9 /usr/local/Library/Formula/pypy.rb
1.4.1    git checkout 46c553a /usr/local/Library/Formula/pypy.rb
1.4      git checkout 61dd587 /usr/local/Library/Formula/pypy.rb
1.3      git checkout a546a1f /usr/local/Library/Formula/pypy.rb
1.2      git checkout 89de8bb /usr/local/Library/Formula/pypy.rb

编辑: 或者,您是否已检查是否已将安装放在路径上?例如,我抓住它并将其放入我的主目录。

~ $ ll ~/ | grep pypy
drwxr-xr-x@  9 squiddly  staff    306 Nov 27 07:42 pypy-2.2.1-osx64

然后在我的.bash_profile中我将以下行放入:

# Put pypy on my path
PATH=$PATH:$HOME/pypy-2.2.1-osx64/bin
export PATH

现在我可以从任何地方运行pypy~ / scripts / test.py。

----编辑2 ---- 要回答关于丢失包裹的最后一个问题:

“如果你想安装第三方库,最方便的方法是安装distribute和pip:”

$ curl -O http://python-distribute.org/distribute_setup.py
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ ./pypy-2.1/bin/pypy distribute_setup.py
$ ./pypy-2.1/bin/pypy get-pip.py
$ ./pypy-2.1/bin/pip install pygments  # for example

“第三方库将安装在pypy-2.1 / site-packages中,脚本安装在pypy-2.1 / bin”

- 从这里:http://doc.pypy.org/en/latest/getting-started.html#installing-pypy