Hey all, I am observing a weird behavior from Pluto. While trying to load the Bandits package (available at Bandits ), I realised the package was not declared in the registry. This forced me to add the command Pkg.add(url=“GitHub - rawls238/Bandits.jl: Implementation of multi-armed bandits in Julia”) to my notebook. Although it loads the Bandits package, it cannot load any other package with the “using” keyword. I must use Pkg.add() Is that expected behavior? Did I miss a configuration?
That’s how Pluto works. Either it automatically adds all packages before using
and removes them once the cell with using
is deleted, but you can only use registered packages, or you go with the general Pkg
mechanism.
A workaround is to create a local registry (see LocalRegistry.jl), register anything you need there, add it in REPL through pkg"registry add myregistry"
, and then Pluto can use packages registered there the same way as the packages from the General registry.
And if you want to share the notebook, you need to add
pkg"registry add myregistry"
inside the notebook?
I tried using
begin
Pkg.pkg"registry add https://github.com/myLocalRegistry"
using mylocalPkg
end
it works on my local machine but does not with CI from GitHub - JuliaPluto/static-export-template: A template to automatically convert Pluto notebooks to an HTML website with GitHub Pages. Demo page:.
It just fails to install.
I also get
┌ Warning: Pkg operation failed. Updating registries and trying again...
└ @ GracefulPkg /srv/julia/pkg/packages/GracefulPkg/LmTcK/src/apply strategies.jl:92
It seems it cannot be done from Pluto with the native pkg management, see:
and
I’ve just discovered this pattern
try
using Bandits
catch notfound
using Pkg
RegistrySpec(url = "https://github.com/myLocalRegistry.git") |> Pkg.Registry.add
error("The registry https://github.com/myLocalRegistry has been added; you need to restart your Pluto session")
end
That way, if the registry has been added, Pluto simply loads the package. Otherwise, it adds the registry before showing a message asking to restart the notebook.
Note that “Restart notebook” button which shows would not suffice. One needs to go to Pluto main menu, kill the notebook from there and start it again.
That should work thanks. However, in terms of user experience, it is not fun!