How to use PyPy on a Mac?

Lucien S. picture Lucien S. · Dec 10, 2013 · Viewed 12.5k times · Source

PyPy's speed promises make me want to try it. Unfortunately, none of the tutorials I read on the subject really helped me to understand the very basics, namely how to (in simple steps):

  • Install PyPy on Mac
  • Run a .py script

I read that downloading, extracting and running pypy myscript.py from bin/ should do the trick, but no luck for me so far. Here's what I get:

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

Could anyone help me understand PyPy's basic usage?

Answer

John P. Neumann picture John P. Neumann · Dec 10, 2013

Have you tried using homebrew (http://brew.sh/)?

~ $ brew search pypy
pypy

Looks like a "brew install pypy" should get you there.

~ $ 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

edit: Alternatively have you checked whether or not you've put your install on your path? For instance, I grabbed it and put it into my home directory.

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

Then in my .bash_profile I put the following line in:

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

Now I can run pypy ~/scripts/test.py from wherever I want.

---- edit 2 ---- To answer the last question regarding the packages being missing:

"If you want to install 3rd party libraries, the most convenient way is to install distribute and 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

"3rd party libraries will be installed in pypy-2.1/site-packages, and the scripts in pypy-2.1/bin"

-- from here: http://doc.pypy.org/en/latest/getting-started.html#installing-pypy