4

I have my own Julia package called foo which is stored in /private/tmp/foo and looks like:

foo
├── Project.toml
└── src
    └── foo.jl

I'd like to use it in an experiment I'm going to run. As such I

  1. Create a new dir called bar for my experiments
  2. Create a new Julia env to use Julia, ],activate .
  3. I now install foo with (bar) pkg> dev /private/tmp/foo

I can now use foo within bar

julia> import foo
[ Info: Precompiling foo [79e59c38-1f99-4492-a045-e17729c6f495]

julia> foo.greet()
Hello World!

I now install Pluto with (bar) pkg> add Pluto, and open a new Pluto notebook. Even though I’m still in the bar env, which has foo installed I get a ArgumentError: Package foo not found in current path: as shown in the image below.

Pluto cannot find foo

How can I create my own module, install and use it within a notebook? Ideally with Revise.jl still working.

this_josh
  • 333
  • 2
  • 11

1 Answers1

3

Even though I’m still in the bar env,

Have you checked that you are still in it? Did you manually activate the environment?

In recent versions, Pluto notebooks have their own individual environments that are stored inside the notebook file. You can either:

begin
    import Pkg
    # activate the shared project environment
    Pkg.activate(Base.current_project())
    # instantiate, i.e. make sure that all packages are downloaded
    Pkg.instantiate()

    import foo
end
Sundar R
  • 13,776
  • 6
  • 49
  • 76
  • Interesting, coming from my experience of Jupiter notebook I expected the Pluto notebook ran in the same env which launched it from. It seems I should read up on how Pluto manages packages Using `Pkg.develop(path="/private/tmp/foo")` in the notebook works – this_josh Feb 04 '22 at 08:02
  • The lack of managing its own environment is one of the reasons why results in Jupyter notebooks are often difficult to reproduce. The Pluto package manager solves this issue. It would be great if Pluto also supports dev packages or non-default package versions with its own package manager, but this is on the long-term agenda. – lungben May 02 '22 at 10:01