ericmjl
ericmjl

Reputation: 14694

Is it possible to run a pypy kernel in the Jupyter notebook?

I have always wondered if it were possible to run PyPy in the Jupyter notebook. I recently tried installing PyPy on my local machine, and it ran really well - 100X speedup in an agent-based simulation written in pure Python. However, I miss the interactivity in the Jupyter notebook. Is it possible to make the IPython kernel use PyPy rather than CPython?

Upvotes: 25

Views: 15496

Answers (5)

Ioannis Nasios
Ioannis Nasios

Reputation: 8527

(Tested in Ubuntu Linux)
To install pypy, make a virtual environment and run jupyter notebook as with python:
Download pypy version (3.8 example here)
in a terminal run following commands to decompress

tar xf pypy3.8-v7.3.9-linux64.tar.bz2 

upgrade pip and wheel

./pypy3.8-v7.3.9-linux64/bin/pypy -m ensurepip --default-pip
./pypy3.8-v7.3.9-linux64/bin/pypy -mpip install -U pip wheel

create virtual env the following way is crucial

./pypy3.8-v7.3.9-linux64/bin/pypy -m venv my-pypy-env   

activate environment

source my-pypy-env/bin/activate

pip install jupyter and any other library

pip install jupyter

open jupyter as always

jupyter notebook

Upvotes: 1

jadelord
jadelord

Reputation: 1765

Provided you have a system-wide / user installation of jupyter. You can follow:

pypy3 -m venv PyPy3
source PyPy3/bin/activate  # in POSIX, or...
PyPy3\Scripts\activate.bat  # in Windows
pypy3 -m pip install ipykernel
ipython kernel install --user --name=PyPy3

Now exit the virtual environment and verify installation:

jupyter kernelspec list

Open Jupyter notebook or lab interface.

Upvotes: 20

PaleNeutron
PaleNeutron

Reputation: 3215

Maybe we can follow the official doc:

pypy3 -m pip install ipykernel
pypy3 -m ipykernel install --user

Upvotes: 1

Zeev
Zeev

Reputation: 11

The first answer worked great for me on Ubuntu, but did not work on Fedora - zeromq failed to compile

The following worked for me, based on the first answer:

$ cd <portable-pypy-directory>
$ bin/python3 virtualenv/virtualenv.py <new-venv-dir>
$ <new-venv-dir>/bin/activate
$ pip install jupyter
$ ipython kernel install --user --name=PyPy3

Upvotes: 1

Mike M&#252;ller
Mike M&#252;ller

Reputation: 85482

You can install Jupyter with pypy:

pypy-pip install jupyter

The are problems on Mac OS X. If the install fails complaining a about gnureadline. Try this:

pypy-pip install --no-deps jupyter

Than start with:

pypy-ipython notebook

My pypy-ipython looks like this:

#!/usr/local/bin/pypy

# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

In a notebook:

In [1]: import sys

In [2]: sys.version

Out[2]:

'2.7.9 (295ee98b6928, May 31 2015, 07:28:49)\n[PyPy 2.6.0 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]'

The notebook requires Python 2.7 or 3.3+. PyPy for Python3.3 should be out soon.

My pypy-pip this executable file /usr/local/bin//pypy-pip with this content:

#!/usr/local/bin/pypy
# EASY-INSTALL-ENTRY-SCRIPT: 'pip','console_scripts','pip'
__requires__ = 'pip'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip', 'console_scripts', 'pip')()
    )

Upvotes: 12

Related Questions