Often we need to get only the error message and the code in Python without the full stack trace.

To display only the Error message in Python and JupyterLab we can use the following codes:

from functools import partial
get_ipython().showtraceback = partial(get_ipython().showtraceback,exception_only=True)

or

from functools import partial
f = get_ipython().showtraceback
tb = partial(f,exception_only=True)
get_ipython().showtraceback = tb

Executed this as a first cell in JupyterLab will show only the error message as shown on the image below:

Show 'Error message' Without Stack Trace in JupyterLab

As alternative solution print an error message without printing a traceback is to catch the error message as instance:

try:
	open("epik.sjj")
except Exception as inst:
	display(inst)

Again this will print only the error message without the traceback - this time without the error formatting:

how-to-show-error-message-without-stack-trace-in-python

Reference