rdeits / MeshCat.jl

WebGL-based 3D visualizer in Julia
MIT License
234 stars 43 forks source link

Cannot establish a connection to the visualizer in Julia v1.11 w Pluto nb #258

Closed RobbesU closed 1 week ago

RobbesU commented 1 week ago

This seems very similar / same as https://github.com/rdeits/MeshCat.jl/issues/234, but now in Julia 1.11 and Pluto notebook. Environment is Windows 11, browser either FireFox or Edge. Meshcat server appears to start, browser opens a new tab automatically and tries to connect, but then fails to connect.

Using MeshCat
begin
    visualizer = Visualizer()
    open(visualizer)
    setvisible!(visualizer, true)
    wait(visualizer)
end
MeshCat server started. You can open the visualizer by visiting the following URL in your browser:
http://127.0.0.1:8700

Error msg in browser: Firefox can’t establish a connection to the server at 127.0.0.1:8700. I've double checked the firewall and despite no block notifications I have set up exemptions anyhow, no difference.

RobbesU commented 1 week ago

Ah.. Further to above: Pkg.status() reports

Status `C:\Users\_____\AppData\Local\Temp\jl_Svmmsh\Project.toml`
⌅ [283c5d60] MeshCat v0.14.2
  [44cfe95a] Pkg v1.11.0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`

with Pkg.status(outdated=true) giving

Status `C:\Users\robur\AppData\Local\Temp\jl_Svmmsh\Project.toml`
⌅ [283c5d60] MeshCat v0.14.2 (<v0.16.2) [compat]

So it looks despite being a fresh installl this has still picked up the (old) v0.14.2, whilst https://github.com/rdeits/MeshCat.jl/issues/234 was fixed in v0.15 onward.

RobbesU commented 1 week ago

Right... forced a Pkg update to MeshCat v1.0.0 and now working,

ferrolho commented 1 week ago

~Hi @RobbesU, I don't have a Windows machine available right now to test this. Can you try updating MeshCat to v1.0.0?~ Never mind, glad you have solved it! :D

RobbesU commented 1 week ago

FWIW (might help others in future), before I could force MeshCat to 1.0.0 I had to first manually remove Blink, Mux and WebSockets note: I'm still fairly new to Julia so apologies if this isn't the proper way to do this in Pluto.

# must include the outdated packages that held back MeshCat before can remove
using Pkg, Blink, Mux, WebSockets
# remove them
Pkg.rm(["Blink","Mux","WebSockets"])
# now update MeshCat
Pkg.add(name="MeshCat",version="1.0.0")
ferrolho commented 1 week ago

Maybe what might also be happening is that you are installing all these packages into your default Julia environment instead of to a specific project.

RobbesU commented 1 week ago

@ferrolho true and i'll have to move to project, but ... It also turns out that it is MeshCatMechanisms v0.9.0 keeps forcing MeshCat back to v0.16.0 from v1.0.0.
So whilst I can run the MeshCat only MWE, it doesn't work for anything more useful as that requires MeshCatMechanism. Any thoughts?

(@v1.11) pkg> status
Status `C:\Users\robur\.julia\environments\v1.11\Project.toml`
  [283c5d60] MeshCat v1.0.0
  [4722fa14] PkgAuthentication v2.0.3
  [c3e4b0f8] Pluto v0.20.3

(@v1.11) pkg> add MeshCatMechanisms
   Resolving package versions...
    Updating `C:\Users\robur\.julia\environments\v1.11\Project.toml`
⌅ [283c5d60] ↓ MeshCat v1.0.0 ⇒ v0.16.2                                 #<<<<<<<<<<<<<<<<<<<<<<<<
  [6ad125db] + MeshCatMechanisms v0.9.0
    Updating `C:\Users\robur\.julia\environments\v1.11\Manifest.toml`
RobbesU commented 1 week ago

I'm fairly new to Julia & Pluto, so I might not be doing this correct, but as I understand it from Pluto docs below installs the packages specifically in project environment by using a Pluto Pkg cell

begin
    import Pkg
    # activate a temporary environment
    Pkg.activate(mktempdir())
    Pkg.add([
        Pkg.PackageSpec(name="MeshCatMechanisms", version="0.9.0"),
        Pkg.PackageSpec(name="MeshCat", version="1.0.0"),
    ])
    Pkg.add("MeshCatMechanisms")
    using MeshCatMechanisms, MeshCat
end

Results in error

Unsatisfiable requirements detected for package MeshCatMechanisms [6ad125db]:

 MeshCatMechanisms [6ad125db] log:

 ├─possible versions are: 0.0.1 - 0.9.0 or uninstalled

 ├─restricted to versions 0.9.0 by an explicit requirement, leaving only versions: 0.9.0

 └─restricted by compatibility requirements with MeshCat [283c5d60] to versions: uninstalled — no versions left

   └─MeshCat [283c5d60] log:

     ├─possible versions are: 0.1.0 - 1.0.0 or uninstalled

     └─restricted to versions 1.0.0 by an explicit requirement, leaving only versions: 1.0.0

Instead, first installing MeshCat v1.0.0, then MeshCatMechanisms results in downgrade of MeshCat to v0.16.2

begin
    import Pkg
    # activate a temporary environment
    Pkg.activate(mktempdir())
    Pkg.add([
# COMMENT OUT    #Pkg.PackageSpec(name="MeshCatMechanisms", version="0.9.0"),    
        Pkg.PackageSpec(name="MeshCat", version="1.0.0"),
    ])
    Pkg.add("MeshCatMechanisms")
    using MeshCatMechanisms, MeshCat
end

Results in

 Activating new project at `C:\Users\robur\AppData\Local\Temp\jl_Pk2ExH`
   Resolving package versions...
    Updating `C:\Users\robur\AppData\Local\Temp\jl_Pk2ExH\Project.toml`
  [283c5d60] + MeshCat v1.0.0
    Updating `C:\Users\robur\AppData\Local\Temp\jl_Pk2ExH\Manifest.toml`
  [d1d4a3ce] + BitFlags v0.1.9
  [944b1d66] + CodecZlib v0.7.6
    .......
  [3f19e933] + p7zip_jll v17.4.0+2
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
   Resolving package versions...
    Updating `C:\Users\robur\AppData\Local\Temp\jl_Pk2ExH\Project.toml`
⌅ [283c5d60] ↓ MeshCat v1.0.0 ⇒ v0.16.2
  [6ad125db] + MeshCatMechanisms v0.9.0
    Updating `C:\Users\robur\AppData\Local\Temp\jl_Pk2ExH\Manifest.toml`
⌅ [79e6a3ab] + Adapt v3.7.2
   ......
ferrolho commented 1 week ago

It also turns out that it is MeshCatMechanisms v0.9.0 keeps forcing MeshCat back to v0.16.0 from v1.0.0.

That's right. It's because v0.9.0 of MeshCatMechanisms.jl is not compatible with the latest version of MeshCat.jl v1.0. I have an open PR for MeshCatMechanisms.jl v0.9.1 (here) which will fix this compatibility issue.

In the meantime, you can work around this problem by installing v0.9.1 of my fork of MeshCatMechanisms.jl on the Julia REPL with

] add https://github.com/ferrolho/MeshCatMechanisms.jl.git#hf/upstream-changes

or via a Pluto/Jupyter notebook cell with

Pkg.add(url="https://github.com/ferrolho/MeshCatMechanisms.jl", rev="hf/upstream-changes")
RobbesU commented 1 week ago

Thanks!