[pypy-issue] Issue #2690: Importing module when PyPy is kernel for Jupyter Notebook (pypy/pypy)

acoady issues-reply at bitbucket.org
Sun Oct 29 14:17:04 EDT 2017


New issue 2690: Importing module when PyPy is kernel for Jupyter Notebook
https://bitbucket.org/pypy/pypy/issues/2690/importing-module-when-pypy-is-kernel-for

acoady:

I encountered a problem when pypy is configured as a kernel for a Jupyter Notebook and I tried to import a module that contains calls the display() rountine in the IPython.display package.  This problem does not occur when pypy3 is configured as the kernel for the Jupyter Notebook nor when Python2 or Python3 is configured as the kernel. It only occurs when pypy for Python2 is configured as the kernel.

What happens is that when you execute the code to import a module that calls IPython.display.display() routine the kernel hangs and the import never completes.

I have jupyter installed on an ubuntu linux machine using Anaconda with Python 3. I also installed pypy and pypy3 on the ubuntu linux machine and configured them as kernels for the Jupyter notebook. When I open a notebook I am able to switch between the 3 kernels, namely Python3 , PyPy and PyPy3. The problem I am having is that the following import statement fails when PyPy is configured as the kernel for the notebook.

from test import *

executing this line in a notebook cell fails when PyPy is the kernel for the notebook, but it works fine when the notebook is configured to have the PyPy3 kernel or the Python3 kernel. It also works fine when Python2 is the kernel. The contents of the test.py file is the following.

import IPython
from IPython.display import display
a = 1
display(a)

When I execute the cell containing

from test import *

when PyPY is the kernel the cell execution never completes and the * symbol remains displayed to the left of the cell indefinitely.

If I put the contents of test.py in a notebook cell and execute the cell it works fine on pypy. It's only when I try to import test that the system hangs.

To recreate the problem you need to install Jupyter, 

http://jupyter.org/install.html

and also install pypy and pypy3.

Next you need to configure pypy as a kernel for the jupyter notebook following these steps.

Step 1: Download PyPy and install pypy on your machine

          https://pypy.org/download.html

Step 2: Add the installed path to pypy on your machine to your PATH environment variable

Step 3: Add pip to PyPy from the terminal window

            pypy -m ensurepip

Step 4: pip install notebook and its dependencies to pypy

            pypy -m pip install notebook

Step 5:  Add pypy kernel to Jupyter Notebook

            pypy -m ipykernel install --user --name pypy --display-name "Python (PyPy)"

If these steps were successful, then you should see the PyPy kernel as one of the available kernels in the Jupyter Notebook. From the terminal window run

    jupyter notebook 

which launches the jupyter notebook in a browser window. Then click the "file" button in the notebook and you should see "Python (PyPy)" as a kernel that you can use. Select PyPy to create a PyPy notebook. Then in the cell of the notebook type.

import sys
sys.version

and execute the cell. It should indicate that it is using PyPy.

To execute a cell with python code in a jupyter notebook you click on the cell and then use the key sequence (Shift+Enter) to execute the python code in the cell.

With pypy as the kernel try executing the contents of the test.py code in a notebook cell.

import IPython
from IPython.display import display
a = 1
display(a)

Then execute this code in the cell  (Shift+Enter) key sequence.

Next try importing test.py in a notebook cell.

from test import *

and you will see that it hangs when pypy for Python 2 is the kernel. It works fine for all other kernels.

To change the kernel in a Jupyter Notebook you can use the menu in an open notebook. (Kernel -> Change Kernel ) . You can also restart the kernel using the Kernel menu item in the open notebook.




More information about the pypy-issue mailing list