Pluto not respecting project environment

I have been struggling to setup Pluto notebook with proper environment.

export JULIA_PROJECT=`pwd`
julia --project=. -e "using Pluto; Pluto.run()"

# in Pluto
using Pkg
Pkg.installed()

> Dict {}

While Pluto does offer to install packages afresh, I could not identify packages present in Project.toml.

I have also tried launching from julia REPL (which does work as expected). Does anyone one know how to setup Pluto for local environment properly?

I have also tried activation manually

Pkg.activate(".")
Pkg.activate("Project.toml")

But no avail.

Julia: 1.6
Pluto 0.15.1

1 Like

When you create a new notebook Pluto puts it with a temporary name under ~\.julia\pluto_notebooks
So if you simply tried to create a new notebook and do

begin
	import Pkg
	Pkg.activate(".")
end

You would not be activating the path from where you started Julia, but the temporary pluto_notebook subfolder.

Try either saving the notebook inside your project folder, or giving the full path of your project to Pkg.activate().

All of this is due to the new integrate package manager that shipped with Pluto v0.15.0 that is described in more detail here:

7 Likes

It is best to use the built-in package management, then you just need to import / using external packages. Pluto automatically pins the versions for reproducibility.

You only need to manage Pkg environments on your own if you are using unregistered packages, local dev packages or specific package git branches. Instructions for these cases are given in the link posted by @disberd .

2 Likes

@lungben It would be nice to do that, however every time I start Pluto, it offers me to install everything, rather then using the local Project.toml. Is there anyway to use Pluto’s own package manager on already defined Project.toml

@disberd Thanks, it worked as expected.

The built-in package manager has the Project.toml and Manifest.toml integrated in the notebook.jl file. If the packages are already installed, Pluto does not re-install them, analogue to activating a Project.toml file (what is actually done under the hood).
To use an external Project.toml file see here: 🎁 Package management · fonsp/Pluto.jl Wiki · GitHub
Combining both approaches is not possible because it would be ambiguous.

4 Likes

I am also struggling with this. I have this structure:

root/
... Project.toml
... Manifest.toml
... notebooks/
...... notebook.jl
... src/
...... Db.jl

Inside notebooks/notebook.jl I try to import Db but I can’t get it to work. I tried adding

begin
   import Pkg
   Pkg.activate()
   Pkg.instantiate()
end

and it does seem to install local packages but the using Db statement still doesn’t work inside the notebook. In the classical Julia REPL this works for me.

Have you tried Pkg.activate("..")?
If I remember correctly, the notebook dir is the current dir, and your Project.toml is one directory up.

Totally agree with the great advice given above. I also like using:

Pkg.activate(Base.current_project())

(included in the “shared environment” link @lungben shared above) if my notebooks are deeper down and I don’t want to manually keep track of how many ../../ I need to do. It’s my understanding that it has the same behavior as --project=@., which is super handy!

3 Likes

OK but for some reason the import Db doesn’t work still (package Db not found in current path).

Ok, are you doing something like this already in one of your cells?

begin
	import Pkg
	Pkg.activate(Base.current_project())
	import Db
end

I made a dummy package for Db.jl, and things seems to work as expected:

Here’s the corresponding repo for it, just to make sure I am on the same page as you

1 Like

OK your code works while mine doesn’t. I have to analyze this deeper then, thank you!

Ah OK I see what’s wrong. My package name is Analyzer while in src I have multiple files, Analyzer.jl, Db.jl etc. So import Analyzer works while import Db doesn’t. Same in your project. If I add src/Db2.jl then using Db2 won’t work.

Seems that adding include("Db2.jl") inside Db.jl works. Now I can run Db.Db2.xxx().