Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

How do you get Visual Studio Code to show Jupyter Python error messages when running a cell in a notebook?

Consider the following Python code segment:

from ipywidgets import Text, Button, Label, VBox, HBox, GridBox, Layout
def on_click(btn):
  value.value += btn.description
def on_click_equals(btn):
    value.value = eval(value.value)

The above code implements a simple calculator that evaluates a mathematical expression when a user clicks on the "=" button in a Jupyter notebook.

When I run this code on somebody else's Jupyter notebook (hosted on a server somewhere on the internet ), I get the following error message:

The 'value' trait of a Text instance must be a unicode string, but a value of 7 <class 'int'> was specified

However, when I run the same code in my local Visual Studio Code Jupyter notebook, I get no error message.

If I change the Python code above to look like:

from ipywidgets import Text, Button, Label, VBox, HBox, GridBox, Layout
def on_click(btn):
  value.value += btn.description
def on_click_equals(btn):
    value.value = str(eval(value.value))     #<--- adding str() fixed the problem

Then everything works correctly in both Visual Studio Code and on the other person's Jupyter server.

My question is: Why couldn't I see the error message in Visual Studio Code? How do I get Visual Studio Code to display Jupyter error messages like:

The 'value' trait of a Text instance must be a unicode string, but a value of 7 <class 'int'> was specified

just like error messages were displayed on the other person's Jupyter server on the internet?

question from:https://stackoverflow.com/questions/66051313/how-do-you-get-visual-studio-code-to-show-jupyter-python-error-messages-when-run

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...