Jupyterhub notebook cant import tensorflow or numpy

I have followed the Jupyterhub installation instructions and built it from the ground up on ubuntu 18.04 . I am unable to import tensorflow or numpy. When i test for them using python outside of jupyter, they are working fine. Jupyter is unable to import them.

Please look at this link for stack trace.

You’ve got two different versions of Python there (3.6 and 3.7) and a note prefaced by being highlighted in CAPS indicating that could be an issue with 3.6 and numpy version 1.18.1:

Traceback (most recent call last):
  File "/opt/jupyterhub/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-579f5beb11ce>", line 3, in <module>
    import tensorflow as tf
  File "/home/yaswanth/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 101, in <module>
    from tensorflow_core import *
  ...

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
...
- If you have already done that, then:
  1. Check that you expected to use Python3.6 from "/opt/jupyterhub/bin/python3",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.

Did you absolutely need multiple versions?
Specifically, it looks like your Jupyterhub has 3.6 and so when you test outside of Jupyter, you are probably using 3.7, and then your imported packages work fine. Run import sys; print (sys.version) and which python in both places and I think you’ll see the difference.

You say you followed ‘the’ JupyterHub installation instructions. It may help people advise you further if you specify from where? There is Zero to JupyterHub with Kubernetes and the Littlest JupyterHub and probably other sets of instructions out there.

2 Likes

Thank you for the insight, it was indeed an issue of multiple python versions. I resolved it after installing necessary modules in Jupyterhub’s python 3.6 path.

I was following the Jupyterhub setup from the ground up installation instructions.
https://jupyterhub.readthedocs.io/en/stable/installation-guide-hard.html

1 Like