WolframResearch / WolframLanguageForJupyter

Wolfram Language kernel for Jupyter notebooks
MIT License
1.05k stars 126 forks source link

Cannot import data as PNG format #119

Closed FlyingSamson closed 2 years ago

FlyingSamson commented 2 years ago

What I observe

When I run, e.g.,

Solve[x==1]

in the Wolfram Language kernel I get no output and the following error messages in the jupyter log:

Import::fmterr: Cannot import data as PNG format.

Import::fmterr: Cannot import data as PNG format.

Import::fmterr: Cannot import data as PNG format.

General::stop: Further output of Import::fmterr

     will be suppressed during this calculation.

StringJoin::string: 

   String expected at position 2 in 

    <img alt="Output" src="data:image/png;base64,<>failedinBase64<>">.

StringJoin::string: 

   String expected at position 2 in 

    <div><img alt="Output" src="data:image/png;base64,<>failedinBase64<>"></div>.

Export::jsonstrictencoding: Expression StringJoin cannot be exported as JSON.

What I expect:

To see the formula as embedded picture.

What I already tried/figured out:

The latter one

StringJoin::string: 

   String expected at position 2 in 

    <img alt="Output" src="data:image/png;base64,<>failedinBase64<>">.

is due to a typo at this line where it should read failedInBase64 (capital "I").

The other ones

Import::fmterr: Cannot import data as PNG format.

are produces at this call to ExportByteArray, but I was unable to figure out what the problem was. If I run above code in wolfram within the command line of the same docker container (in fact I used a terminal provided by the very same JupyterLab instance) I get the expected result

In[1]:= Solve[x==1]                                                                                                                                                                                                                                                     

Out[1]= {{x -> 1}}

Moreover all inputs resulting in plaintext output like Print["Hello"] or 1+1 do work as expected in the notebook displaying "Hello" and "2", respectively, so apparently something goes wrong with results that are returned as images.

How can I debug this issue? For a start how can I print/log what is actually passed to the ExportByteArray call? Is there some logging functionality build into the kernel that would allow to append messages to the jupyter log?

My environment:

FlyingSamson commented 2 years ago

So I just tried replacing the export formats with "JPEG" instead of "PNG" and this works. I presume this is an indicator that there is some problem with my installation of the wolfram engine and/or its dependencies rather than with the Wolfram Language Kernel For Jupyter?

benfre commented 2 years ago

I also find this problem on raspberry os, $Version -> "12.2.0 for Linux arm (32-bit)"

To anyone want to know the "JPG" fix, it's changing Format from "PNG" to "JPG" in call to ExportByteArray[] in function toImageData[] "Resources/OutputHandlingUtilities.wl".

FlyingSamson commented 2 years ago

I just posted this as a question to the wolfram community. @benfre: Is your jupyter notebook running on the raspberry os itself, or also within a docker container (as in my case). If it is running on raspberry os itself, can you confirm that this is happening inside the wolfram console also, i.e., when you execute wolfram in terminal and run the command I mentioned in the linked post

Export["test.png", Plot[x, {x, 0, 1}]]

do you get the same error message?

okofish commented 2 years ago

@FlyingSamson @benfre Thanks for identifying this issue. I'm told that it's been reproduced and is under investigation.

FlyingSamson commented 2 years ago

This is now fixed with the latest update to Mathematica 13.0.1