24

I"m going through this tutorial to set up pytorch (v1.3.0 through conda) with tensorboard https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html#

but on the step

from torch.utils.tensorboard import SummaryWriter

# default `log_dir` is "runs" - we'll be more specific here
writer = SummaryWriter('runs/fashion_mnist_experiment_1')

I keep getting the error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      1 try:
----> 2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:

ModuleNotFoundError: No module named 'tensorboard.summary'; 'tensorboard' is not a package

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
c:\Users\matt\Documents\code\playground\tensorboard.py in 
----> 1 from torch.utils.tensorboard import SummaryWriter
      2 
      3 # default `log_dir` is "runs" - we'll be more specific here
      4 writer = SummaryWriter('runs/fashion_mnist_experiment_1')

C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:
----> 4     raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
      5                       'This should be available in 1.14 or above.')
      6 from .writer import FileWriter, SummaryWriter  # noqa F401

ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.

Does anyone have any suggestions?

kmario23
  • 57,311
  • 13
  • 161
  • 150
foobar8675
  • 1,215
  • 3
  • 16
  • 26

5 Answers5

17

The error log says, among other things,

ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.

So, when it tries to import TensorBoard, it's unable to do so because it's missing it in the search path. You can install the latest version (without specifying any version number), as in:

$ conda install -c conda-forge tensorboard

Apart from that, you might also need to install protobuf:

$ conda install -c conda-forge protobuf

These installations should fix the ImportErrors.

kmario23
  • 57,311
  • 13
  • 161
  • 150
6

I came across the same error, I solved by taking the following steps:

  1. Removed all installation of Tensorflow or Tensorboard from the conda environment.
  2. Then by activating the same conda environment, type "pip install -U tb-nightly"
  3. Then type, "pip install -U future"
  4. done
  • 1
    hi, thanks for the comment. i tried uninstalling everything, conda remove tensorflow, conda remove tensorboard, pip uninstall tensorflow, pip uninstall tensorboard, then pip installed the 2 packages above but am still getting the error. do you have any suggestions? – foobar8675 Nov 04 '19 at 15:58
  • never mind, this was my problem. https://github.com/tensorflow/tensorflow/issues/29866 . i also had to do what you did above and am marking it correct – foobar8675 Nov 04 '19 at 17:36
  • I followed all the steps and got this error: TypeError: __new__() got an unexpected keyword argument 'serialized_options' – G. Macia Nov 28 '19 at 21:55
  • I am using virtualenvironment and this did not work for me. I did all the steps after pip uninstalling tensorflow and tensorboard. After, I followed the steps in the answer above, installed tensorflow and tensorboard. Then, I opened a notebook in visual studio code and I still have the same error. – desmond13 Apr 22 '20 at 13:06
5

I think it's a version problem.

just run this:

pip install tensorboard==1.14.0

(not pip install tensorboard==1.14)

or just install the tensoflow 1.14.0, which contains the tensorboard 1.14.0:

pip install tensorflow==1.14.0

This version of tensorflow worked for me in pytorch 1.2.

Qiang Na
  • 51
  • 2
1

I've done:

conda install -y tensorboard

before with no problems, so Im not sure why that wouldn't work. It's the simplest.

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
1

I met the same error, and my conda also didn't work that time, so I chose to use tensorboardX, it is almost absolutely the same as tensorboard(also its operations).
Just install it with pip install tensorboardX
And you can import it with from tensorboardX import SummaryWriter

Hu Xixi
  • 1,799
  • 2
  • 21
  • 29