no module named tensorboard.notebook

1,569 views
Skip to first unread message

John Davis

unread,
Apr 28, 2019, 9:46:58 AM4/28/19
to TensorFlow Community Testing
Hello

I am using pip/conda with tensorflow 2.0.  I can not load the module extension for tensorboard.

My setup:
(tf2) VanVan~/progs$ which tensorboard
/anaconda3/envs/tf2/bin/tensorboard
(tf2) VanVan~/progs$ which python
/anaconda3/envs/tf2/bin/python
(tf2) VanVan~/progs$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 15:43:19)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-alpha0
>>> quit()

From within notebook
!echo $PATH
/Users/davis/google-cloud-sdk/bin:/anaconda3/envs/tf2/bin:/anaconda3/condabin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/Users/davis/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/minicom/2.2/bin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Applications/mybin:~/progs/nand2tetris/tools:/Users/davis/Library/Android/sdk/platform-tools:/Users/davis/progs/flutter/bin


That guide mentions a few things of note:
- using tf-nightly-2.0.preview but I assume 2.0.0-alpha is preferred.
- "if you've installed Jupyter and TensorBoard into the same virtualenv, then you should be good to go."  As above shows, I am doing that.
- ensure you tensorboard binary is on your path.  The best I can do in that regard is show the results of which and path inside the jupyter notebook.

FWIW, the load_ext magic works in collab.  I'm trying to get it working in jupyter.  Lastly, I've done things like enable extensions for jupyter notebooks such as 

jupyter nbextension enable --py --sys-prefix widgetsnbextension

I'm wondering if the guide is skipping this part.

--
John F. Davis
6 Kandes Court
Durham, NC 27713
919-888-8358
Public Profile https://www.linkedin.com/in/netskink

独树一帜

Martin Wicke

unread,
Apr 29, 2019, 11:56:04 PM4/29/19
to John Davis, William Chargin, TensorFlow Community Testing
+William Chargin will know best, but I suspect this does require an additional step in jupyter.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Community Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testing+u...@tensorflow.org.

John Davis

unread,
Apr 30, 2019, 10:21:28 AM4/30/19
to Martin Wicke, TensorFlow Community Testing, William Chargin
Possibly it needs something at the command line to enable the module.  I’m not sure really but all the example docs seem to be based on the doc which uses collab as a platform.
--
Rocking the roll like a natural man!

William Chargin

unread,
Apr 30, 2019, 11:30:13 AM4/30/19
to Martin Wicke, John Davis, TensorFlow Community Testing
Hi John,

If the `tensorboard.notebook` module can’t be found, this suggests that
your environment is using an old version of TensorBoard. Sometimes this
can happen if you have both `tensorboard` and `tb-nightly` installed in
your environment, or if you mix Conda and Pip installations.

You don’t need to do anything at the command line to enable the module.
The docs were written with Colab in mind, but I did test them in Jupyter
as well.

Could you try uninstalling both `tensorboard` and `tb-nightly` in your
environment, and then pulling the latest versions of the TF 2.0 preview
and TensorBoard nightly, restarting Jupyter, and trying again? If this
doesn’t work, please provide instructions on how exactly to reproduce
this problem from a blank slate, as well as the output of `pip freeze`
and the value of `__import__("tensorboard").__version__` from inside the
Jupyter notebook context.

(I’m at a conference today and tomorrow so may be slow to respond to
further emails, but others may be able to help you still!)

Best,
WC

John Davis

unread,
Apr 30, 2019, 12:52:14 PM4/30/19
to William Chargin, Martin Wicke, TensorFlow Community Testing
Hello William,

Nice to meet you and thanks for responding.  I do realize you are busy so I want to say thank you immediately.

With that said, here is the pip free output relative to any tensorboard and tensorflow output before I start pruning and reinstalling.
--------------------------
(tf2) Huo-Yang~/progs/tf-hackathon$ conda activate tf2
(tf2) Huo-Yang~/progs/tf-hackathon$ pip freeze | grep tensor
jupyter-tensorboard==0.1.10
tensorflow==2.0.0a0


Removing it and checking version
-----------------------
(tf2) Huo-Yang~/progs/tf-hackathon$ conda remove jupyter-tensorboard
Collecting package metadata: done
Solving environment: failed

PackagesNotFoundError: The following packages are missing from the target environment:
  - jupyter-tensorboard

Looks like its not from conda. Its from pip
-----------------

(tf2) Huo-Yang~/progs/tf-hackathon$ pip uninstall jupyter-tensorboard
Uninstalling jupyter-tensorboard-0.1.10:
  Would remove:
    /anaconda3/envs/tf2/bin/jupyter-tensorboard
    /anaconda3/envs/tf2/lib/python3.7/site-packages/jupyter_tensorboard-0.1.10.dist-info/*
    /anaconda3/envs/tf2/lib/python3.7/site-packages/jupyter_tensorboard/*
Proceed (y/n)? y
  Successfully uninstalled jupyter-tensorboard-0.1.10
(tf2) Huo-Yang~/progs/tf-hackathon$ which tensorboard
/anaconda3/envs/tf2/bin/tensorboard
(tf2) Huo-Yang~/progs/tf-hackathon$ pip freeze | grep tensor
tensorflow==2.0.0a0

Hmm, interesting the command does not have a version option. Not sure at this point what version of tensorboard
is left visible.
--------------------

(tf2) Huo-Yang~/progs/tf-hackathon$ tensorboard --version
tensorboard: error: unrecognized arguments: --version


tensorboard is not installed as a seperate package via conda or pip
---------------

(tf2) Huo-Yang~/progs/tf-hackathon$ conda remove tensorboard
Collecting package metadata: done
Solving environment: failed

PackagesNotFoundError: The following packages are missing from the target environment:
  - tensorboard


(tf2) Huo-Yang~/progs/tf-hackathon$ pip uninstall tensorboard
WARNING: Skipping tensorboard as it is not installed.

Starting jupyter-notebook from this shell/environment and running this code fails
---------
# Load the TensorBoard notebook extension
# Jupyter/colab method?
%load_ext tensorboard 
# Jupyterlab method?
#%load_ext tensorboard.notebook 

<stack trace snipped>
/anaconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'tensorboard '


Shutting down jupyter, unistalling tensorflow via pip, checking if tensorboard is still present.
--------------

Hmm. After I closed and halted the notebook, I went to the "running" tab in jupyter and it showed the following error for the extension.
Jupyter tensorboard extension error
  1. Check that tensorflow(-gpu)>=1.3 is installed.
  2. Check that jupyter, tensorflow and jupyter_tensorboard have the same python version.
  3. Check that jupyter_tensorboard is installed via pip list. If you want uninstall this extension, run jupyter nbextension disable jupyter_tensorboard/tree --user and jupyter nbextension uninstall jupyter_tensorboard --user;
  4. Copy your browser console logs to submit a new issue in https://github.com/lspvic/jupyter_tensorboard

Do the part for uninstalling the extension
----------


(tf2) Huo-Yang~/progs/tf-hackathon$ jupyter nbextension disable jupyter_tensorboard/tree --user; jupyter nbextension uninstall jupyter_tensorboard --user;
Disabling notebook extension jupyter_tensorboard/tree...
      - Validating: OK
Removing: /Users/davis/Library/Jupyter/nbextensions/jupyter_tensorboard
(tf2) Huo-Yang~/progs/tf-hackathon$

Restart jupyternotebook, try again, same failure.  This time when I check running the "jupyter tensorboard extension error" above is not present.
--------------
Now truly uninstall tensorflow and reinstall and retry in jupyter notebook.
-----------

(tf2) Huo-Yang~/progs/tf-hackathon$ pip uninstall tensorflow
Uninstalling tensorflow-2.0.0a0:
  Would remove:
    /anaconda3/envs/tf2/bin/freeze_graph
    /anaconda3/envs/tf2/bin/saved_model_cli
    /anaconda3/envs/tf2/bin/tensorboard
    /anaconda3/envs/tf2/bin/tf_upgrade_v2
    /anaconda3/envs/tf2/bin/tflite_convert
    /anaconda3/envs/tf2/bin/toco
    /anaconda3/envs/tf2/bin/toco_from_protos
    /anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow-2.0.0a0.dist-info/*
    /anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow/*
Proceed (y/n)? y
  Successfully uninstalled tensorflow-2.0.0a0
(tf2) Huo-Yang~/progs/tf-hackathon$ pip freeze | grep tensor
(tf2) Huo-Yang~/progs/tf-hackathon$

Reinstall tensorflow
-------------

(tf2) Huo-Yang~/progs/tf-hackathon$ pip install tensorflow==2.0.0-alpha0

Retry jupyter notebook
-----------------------

Same error as before.  Here is the entire stacktrace



---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-d873fe2ff8be> in <module>
      1 # Load the TensorBoard notebook extension
      2 # Jupyter/colab method?
----> 3 get_ipython().run_line_magic('load_ext', 'tensorboard ')
      4 # Jupyterlab method?
      5 #%load_ext tensorboard.notebook

/anaconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2305                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2306             with self.builtin_trap:
-> 2307                 result = fn(*args, **kwargs)
   2308             return result
   2309 

</anaconda3/envs/tf2/lib/python3.7/site-packages/decorator.py:decorator-gen-64> in load_ext(self, module_str)

/anaconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

/anaconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/magics/extension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     34 
     35         if res == 'already loaded':

/anaconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/extensions.py in load_extension(self, module_str)
     78             if module_str not in sys.modules:
     79                 with prepended_to_syspath(self.ipython_extension_dir):
---> 80                     mod = import_module(module_str)
     81                     if mod.__file__.startswith(self.ipython_extension_dir):
     82                         print(("Loading extensions from {dir} is deprecated. "

/anaconda3/envs/tf2/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/anaconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/anaconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/anaconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'tensorboard '


John Davis

unread,
Apr 30, 2019, 1:04:02 PM4/30/19
to William Chargin, Martin Wicke, TensorFlow Community Testing
Hello William,

I forgot to mention, I did pip remove tb-nightly. I also forgot to give the other info you requested.

Regarding the import tensorboard version bit, I'm unsure what you want there.  Running in a cell gives this

__import__("tensorboard").__version__
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-11940607f6f4> in <module>
----> 1 __import__("tensorboard").__version__

ModuleNotFoundError: No module named 'tensorboard'

import tensorflow as tf
print(tf.__version__)
2.0.0-alpha0

Steps to reproduce
1. I installed anaconda using python 3 version.
2. Created a python 3 virt env named tf2.
3. conda activate tf2
4. Install tf2 in this environment
5. (tf2) Huo-Yang~/progs/tf-hackathon$ pip install tensorflow==2.0.0-alpha0
6.   Possibly installed jupyter notebook using conda.  It might have been there already.
7.  conda install jupyter-notebook 

William Chargin

unread,
Apr 30, 2019, 9:03:30 PM4/30/19
to John Davis, Martin Wicke, TensorFlow Community Testing
Okay, so you don’t have TensorBoard installed at all in your notebook
context. This explains why you’re unable to import TensorBoard or load
the notebook extensions.

I can’t reproduce the problem with the below steps:

$ conda create --name tf2-john-davis-20190430
$ conda activate tf2-john-davis-20190430
$ conda install pip
$ pip install tensorflow==2.0.0-alpha0
$ pip install jupyter # or `conda install jupyter`; same result
$ jupyter notebook

When I opened the Jupyter notebook, `import tensorboard` worked fine.

> Possibly installed jupyter notebook using conda. It might have been
> there already.

This may well be the problem, and it is what is referred to in the docs.
If your copy of Jupyter is installed _outside_ the environment—say, as a
system- or user-level package—then the Python path may not be resolved
correctly.

The simplest thing to do is to create a fresh environment without system
site packages, and install everything that you need in that environment.

Best,
WC

John Davis

unread,
May 2, 2019, 10:30:39 AM5/2/19
to William Chargin, Martin Wicke, TensorFlow Community Testing
Hello William,

So uninstalled my anaconda via install anaconda-clean.  Run anaconda-clean, delete backup directory, make sure nothing is left around.

I'm on osx so I simply used spotlight to search for tensorboard.  I did not find any leftover files with that name in the filesystem.

Installed the miniconda cli to get a new conda.  I'm not a fan of how it takes over the system on osx, but whatever.

Then I did exactly what you did above.   


 $ conda create --name tf2
 $ conda activate tf2

 $ conda install pip
 $ pip install tensorflow==2.0.0-alpha0
 $ conda install jupyter
 $ jupyter notebook


BTW I did not know you could do $ jupyter notebook, I thought it was $jupyter-notebook.  That is a good tip thanks.

Regardless, I get the same error as before when I try to load the tensorboard extension.

Reading your message again, you say "When I opened the Jupyter notebook, `import tensorboard` worked fine."

I thought we are trying to resolve, %load_ext tensorboard ?  I can import tensorboard fine as well.  In the guide, it showed the load_ext command
before any import commands.  I tried to do the import beforehand but the error is the same.


BTW, is this current info for TF2.0 tensorboard and notebooks? https://github.com/lspvic/jupyter_tensorboard

This doc does not do an import tensorboard before it loads the tensorboard extension.  Is this out of date or current? https://www.tensorflow.org/tensorboard/r2/tensorboard_in_notebooks
It refers to nightly?  Should we use that or 2.0.0-alpha0?

Also you said, 'This may well be the problem, and it is what is referred to in the docs.'.  What docs?  Which is the one I should be reading?


Lastly, here are the cell commands and their output


!echo $PATH
/Users/davis/miniconda3/envs/tf2/bin:/Users/davis/miniconda3/envs/tf2/bin:/Users/davis/miniconda3/bin:/Users/davis/miniconda3/condabin:/Users/davis/google-cloud-sdk/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/Users/davis/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/minicom/2.2/bin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Applications/mybin:~/progs/nand2tetris/tools:/Users/davis/Library/Android/sdk/platform-tools:/Users/davis/progs/flutter/bin


import tensorflow as tf
print(tf.__version__)
2.0.0-alpha0

import tensorboard

__import__("tensorboard").__version__
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-11940607f6f4> in <module>
----> 1 __import__("tensorboard").__version__

AttributeError: module 'tensorboard' has no attribute '__version__'


# Load the TensorBoard notebook extension
# Jupyter/colab method?
%load_ext tensorboard 
# Jupyterlab method?
#%load_ext tensorboard.notebook 

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-17-d873fe2ff8be> in <module>
      1 # Load the TensorBoard notebook extension
      2 # Jupyter/colab method?
----> 3 get_ipython().run_line_magic('load_ext', 'tensorboard ')
      4 # Jupyterlab method?
      5 #%load_ext tensorboard.notebook

~/miniconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2305                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2306             with self.builtin_trap:
-> 2307                 result = fn(*args, **kwargs)
   2308             return result
   2309 

</Users/davis/miniconda3/envs/tf2/lib/python3.7/site-packages/decorator.py:decorator-gen-64> in load_ext(self, module_str)

~/miniconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/miniconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/magics/extension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     34 
     35         if res == 'already loaded':

~/miniconda3/envs/tf2/lib/python3.7/site-packages/IPython/core/extensions.py in load_extension(self, module_str)
     78             if module_str not in sys.modules:
     79                 with prepended_to_syspath(self.ipython_extension_dir):
---> 80                     mod = import_module(module_str)
     81                     if mod.__file__.startswith(self.ipython_extension_dir):
     82                         print(("Loading extensions from {dir} is deprecated. "

~/miniconda3/envs/tf2/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

~/miniconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/miniconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

~/miniconda3/envs/tf2/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'tensorboard '







Thanks again,

John

William Chargin

unread,
May 2, 2019, 11:41:11 AM5/2/19
to John Davis, Martin Wicke, TensorFlow Community Testing
In your previous email, you posted cell output that showed

ModuleNotFoundError: No module named 'tensorboard'

which indicates that the `tensorboard` module could not be imported.
Loading the TensorBoard extension requires importing the TensorBoard
module, so we need to resolve the module import first (and likely this
will resolve the extension loading error).

No, you do not need to import TensorBoard before loading the notebook
extension. Loading the extension imports the TensorBoard module (but
does not add it to your namespace). By “the docs” I mean the same docs
that you quoted in your original email: “If you’ve installed Jupyter and
TensorBoard into the same virtualenv…”.

In your most recent email, I see that you are now receiving

ModuleNotFoundError: No module named 'tensorboard '

with a trailing space. Make sure to run `%load_ext tensorboard` without
a trailing space in the cell: not `%load_ext tensorboard `.

Furthermore, the `module 'tensorboard' has no attribute '__version__'`
error indicates that you are not on the most recent version of
TensorBoard (the `__version__` alias was added in #2026 on 2019-03-19),
and so consequently you will need to either (a) upgrade to a more recent
`tb-nightly` or (b) use `%load_ext tensorboard.notebook` instead. The
notebook extension endpoint does not differ between Jupyter, Colab, and
Jupyterlab, but rather on the version; `tensorboard.notebook` was the
beta endpoint, and the stable endpoint is now `%load_ext tensorboard`.

Best,
WC

John Davis

unread,
May 2, 2019, 5:15:20 PM5/2/19
to William Chargin, Martin Wicke, TensorFlow Community Testing
Hello William,

You rock the roll!  When you pointed out the trailing space in this command

%load_ext tensorboard.notebook

I tried that command without a space and it worked.

After that I could do the other commands in the sample so that tensorboard was visible inside a cell within the notebook.

Also FWIW, 

%load_ext tensorboard

gives

The tensorboard module is not an IPython extension.

But at least it does not stack trace.  Using notebook extension and the remaining commands work.  I'm guessing collab notebooks trim trailing spaces but jupyter does not.


You have made my day.   Thanks a bunch!

John

William Chargin

unread,
May 2, 2019, 5:45:20 PM5/2/19
to John Davis, Martin Wicke, TensorFlow Community Testing
Great; glad to hear it!

> The tensorboard module is not an IPython extension.

Right; for older beta versions of the extension you would need to use
`%load_ext tensorboard.notebook`, as mentioned above (and as you figured
out, from the sound of it).

Best,
WC
Reply all
Reply to author
Forward
0 new messages