Using ShareAdd.jl in Pluto.jl

Hi all, I use ShareAdd.jl to manage my shared environments. I also generally use @usingany to use a package without installing it in a project environment (which is very convenient).

However, I tried to use ShareAdd inside a Pluto notebook. In the first cell of the notebook, I import all my packages like

begin
   using Pkg
	Pkg.activate("../.")

	using ShareAdd
    @usingany CairoMakie
end

The cell is executed without error. Unfortunately, when I call a CairoMakie function in another cell, Pluto throws an errors:

begin
	x = 1:10
    lines(x, x)
end

The error message is:

UndefVarError: lines not defined in this notebook.

Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Contour.
Hint: a global variable of this name also exists in Makie.
    - Also exported by CairoMakie (loaded but not imported in Main).

From the error message, I understand that CairoMakie is loaded but not imported in Main. Do you have any advice to solve this issue?

Thank you

Don’t know about @usingany in Pluto, but is there any specific reason you don’t use Pluto’s builtin environment manager? No need to manually install packages into any env then – your whole cell shortens to just using CairoMakie.

I don’t use Pluto builtin environment manager because I use local packages that are not registered.

Here the author of ShareAdd.jl, who has never used Pluto, and not really used Jupiter, too.

What would happen if you do:

using ShareAdd
@usingany CairoMakie
using CairoMakie
# some Makie function in the same cell

and if works, call some Makie function in another cell

You might consider LocalRegistry.jl – it’s very straightforward, and a great fit for this exact scenario.

1 Like

Thanks @Eben60. It works. But may I ask, why did you think that it might work ?

@usingany should

  • make the environment containing the package called available by adding it to LOAD_PATH, and
  • then execute the using statement.

For whatever reason it didn’t work properly, but as you wrote:

I guessed the first part executed OK, and then manual import could be possible. Which then worked.

1 Like