SciNim / nim-plotly

plotly wrapper for nim-lang
https://scinim.github.io/nim-plotly/
MIT License
173 stars 15 forks source link

Cannot find file specifier "/tmp/x.html" on Ubuntu WSL #59

Closed Clonkk closed 4 years ago

Clonkk commented 4 years ago

When I try to run simple example under Ubuntu WSL I have the following error

Start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ Start "/tmp/x.html"
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

However on Windows it run just fine. Is there a way to use this library with WSL ?

Vindaar commented 4 years ago

Funny you open this issue. I've tried plotly under WSL (running Debian though) 2 days ago myself for the first time.

In my experience the problem however was that openDefaultBrowser didn't do anything useful and thus the whole thing couldn't work.

Did you define the BROWSER environment variable or set up xdg-open to work under WSL?

Clonkk commented 4 years ago

Defining as an environment variable BROWSERjust open an empty firefox windows (with no error message) so you're probably on the right direction.

I also tried using WSLU with wslview but it didn't work.

Clonkk commented 4 years ago

So, I tested openDefaultBrowser and it works. Nonetheless, but nim-plotly still doesn't show anything.

It seems the problem is that I'm using firefox.exe under as default WSL2 browser and the path of the file needs to be prefixed. So in plotly_display.nim I have to actually call openDefaultBrowser("file://///wsl$/Ubuntu" & file) .

If I use a "Linux" browser in WSL then it works but most browser I've tried crash when closing (but it's a WSL2 bug, not related).

Vindaar commented 4 years ago

Oh interesting. Does that mean if you modify the openDefaultBrowser in such a way that it works properly?

If so could you check that saving images also works? (by compiling with --threads:on and giving show a string argument for the filename where to store).

Not sure if there's a good way to detect if someone is running code in WSL though. If there is we can modify ploty_display to take that into account.

I tried to get it running on my machine yesterday for a little while longer, but gave up. I just dump it as a JSON file and created the plot on a different linux machine...

Clonkk commented 4 years ago

If you modifiy the filename to have the correct prefix that allow a browser that is a Windows process to access the file correctly then it runs without any issues. If you use a "Linux" Browser it works as well with the problem that most browser don't run smoothly inside WSL (I'm using WSL2). The browser that gave me the less issue was Midori so that's what I'm using at the moment.

One way to detect WSL is to read /proc/version. Maybe it could be done at compile time and defnie a flag -d:wsl to handle this case ? The problem with this approach is that the prefix appears dependent on the distribution.

I'm using the example heatmap and I can't compile with --threads:on, seems there is an error:

/home/rcaillaud/.nimble/pkgs/plotly-0.2.0/plotly/image_retrieve.nim(70, 25) template/generic instantiation of `async` from here
/home/rcaillaud/.nimble/pkgs/plotly-0.2.0/plotly/image_retrieve.nim(81, 65) Error: type mismatch: got <string, HeaderVerificationError>
but expected one of:
macro `&`(pattern: string): untyped
  first type mismatch at position: 2
  extra argument given
proc `&`(x, y: string): string
  first type mismatch at position: 2
  required type for y: string
  but expression 'error' is of type: HeaderVerificationError
proc `&`(x: string; y: char): string
  first type mismatch at position: 2
  required type for y: char
  but expression 'error' is of type: HeaderVerificationError
proc `&`[T](x: T; y: seq[T]): seq[T]
  first type mismatch at position: 2
  required type for y: seq[T]
  but expression 'error' is of type: HeaderVerificationError
4 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them

expression: "Websocket negotiation failed: " & error
Vindaar commented 4 years ago

Cool, that's good to know!

One way to detect WSL is to read /proc/version.

Maybe that can work. Making at an opt-in choice via -d:wsl is definitely a good idea.

Regarding that compilation error. Oh, it seems like something changed in the stdlib on devel. I'll push a fix.

Vindaar commented 4 years ago

Just opened #60 to fix that error.

Clonkk commented 4 years ago

Thanks ! Should the WSL fix proposed could be open on the stdlib level since it actually impacts openDefaultBrowser ?

Vindaar commented 4 years ago

For the time being I think I'll open a PR with a fix just for plotly. Feel free to open a Nim PR though and try to do handle it there. I just don't feel like doing that right now, since I fear the additional work if special casing WSL only within the browsers.nim module is rejected and instead WSL should be introduced as more supported target instead.

Vindaar commented 4 years ago

With #61 merged now, I consider this fixed. Feel free to reopen / open a new issue.