Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'SummaryWriter' #19

Closed
acgtyrant opened this issue Aug 23, 2017 · 11 comments
Closed

ImportError: cannot import name 'SummaryWriter' #19

acgtyrant opened this issue Aug 23, 2017 · 11 comments

Comments

@acgtyrant
Copy link

I do not use anaconda, I install tensorboard-pytorch and tensorflow py pip in the virtual enviroment.

I tried, from tensorboard import SummaryWriter, it complains as the title. However, I find the SummaryWriter is in the writer.py in tensorboard, so I have to use from tensorboard.writer import SummaryWriter. Where am I wrong?

@lanpa
Copy link
Owner

lanpa commented Aug 23, 2017

I think it's the same case as mentioned in #17, and
pip install tensorboardX should solve the problem.

@acgtyrant
Copy link
Author

You are right.

@YangSN0719
Copy link

from tensorboard import summary as summary_lib
from tensorboard.plugins.custom_scalar import layout_pb2

When I was running the following command, an error occurred. I'm sorry to bother you, but please help me anyway

(n2n) [410@mu01 noise2noise-master]$ python config.py validate --dataset-dir=datasets/kodak --network-snapshot=results/network_final-gaussian-n2c.pickle
Traceback (most recent call last):
File "config.py", line 14, in
import validation
File "/home/410/ysn/noise2noise-master/validation.py", line 16, in
import dnnlib.tflib.tfutil as tfutil
File "/home/410/ysn/noise2noise-master/dnnlib/tflib/init.py", line 8, in
from . import autosummary
File "/home/410/ysn/noise2noise-master/dnnlib/tflib/autosummary.py", line 28, in
from tensorboard import summary as summary_lib
ImportError: cannot import name 'summary'

@lanpa
Copy link
Owner

lanpa commented Mar 26, 2019

@YangSN0719 It should be from tensorboardX, not tensorboard.

@soans1994
Copy link

hello,

i have problem please help

import tensorboardX
Traceback (most recent call last):
File "", line 1, in
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/init.py", line 5, in
from .torchvis import TorchVis
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/torchvis.py", line 11, in
from .writer import SummaryWriter
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/writer.py", line 223
logdir: Optional[str] = None,
^
SyntaxError: invalid syntax

@iszff
Copy link

iszff commented Sep 8, 2021

hello,

i have problem please help

import tensorboardX
Traceback (most recent call last):
File "", line 1, in
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/init.py", line 5, in
from .torchvis import TorchVis
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/torchvis.py", line 11, in
from .writer import SummaryWriter
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/writer.py", line 223
logdir: Optional[str] = None,
^
SyntaxError: invalid syntax

I meet this too,have you solved this?/(ㄒoㄒ)/~~

@soans1994
Copy link

hello,
i have problem please help

import tensorboardX
Traceback (most recent call last):
File "", line 1, in
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/init.py", line 5, in
from .torchvis import TorchVis
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/torchvis.py", line 11, in
from .writer import SummaryWriter
File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/writer.py", line 223
logdir: Optional[str] = None,
^
SyntaxError: invalid syntax

I meet this too,have you solved this?/(ㄒoㄒ)/~~

i installed using conda tensorboardx 2.4

@lanpa
Copy link
Owner

lanpa commented Nov 28, 2021

@iszff @soans1994 Please update to python3 for the newer tensorboardX. I should have release the package with a correct metadata. sorry.

@muthena
Copy link

muthena commented Jan 26, 2023

I installed using conda, and run with pytorch, but the wrong below still, how can solve the problem?

Traceback (most recent call last):
File "E:\yolo\content\yolov7\train.py", line 21, in
from torch.utils.tensorboard import SummaryWriter
ImportError: cannot import name 'SummaryWriter' from 'torch.utils.tensorboard' (unknown location)

@Ahmoudahmed
Copy link

Traceback (most recent call last):
File "main.py", line 10, in
from tensorboardX import SummaryWriter
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/init.py", line 5, in
from .torchvis import TorchVis
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/torchvis.py", line 11, in
from .writer import SummaryWriter
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/writer.py", line 27, in
from .event_file_writer import EventFileWriter
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/event_file_writer.py", line 28, in
from .proto import event_pb2
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/proto/event_pb2.py", line 15, in
from tensorboardX.proto import summary_pb2 as tensorboardX_dot_proto_dot_summary__pb2
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/proto/summary_pb2.py", line 15, in
from tensorboardX.proto import tensor_pb2 as tensorboardX_dot_proto_dot_tensor__pb2
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/proto/tensor_pb2.py", line 15, in
from tensorboardX.proto import resource_handle_pb2 as tensorboardX_dot_proto_dot_resource__handle__pb2
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/tensorboardX/proto/resource_handle_pb2.py", line 35, in
_descriptor.FieldDescriptor(
File "/home/reeplayer/anaconda3/envs/env38/lib/python3.8/site-packages/google/protobuf/descriptor.py", line 621, in new
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

@Ahmoudahmed
Copy link

Downgrade protobuf: If upgrading protobuf doesn't solve the issue, you can try downgrading it to a version <= 3.20.x. You can install a specific version like this:
pip install protobuf==3.20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants