# Pluto not respecting project environment

**URL:** <https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308>\
**Category:** New to Julia\
**Tags:** pluto\
**Created:** [July 26, 2021, 3:05pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308 "2021-07-26T15:05:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amit1/32/25318_2.png) [@amit1](https://discourse.julialang.org/u/amit1)\
**Post date:** [July 26, 2021, 3:05pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/1 "2021-07-26T15:05:48Z")

</div>

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

```julia
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

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

```

But no avail.

Julia: 1.6  
Pluto 0.15.1

---

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [July 26, 2021, 3:36pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/2 "2021-07-26T15:36:38Z")

</div>

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

```julia
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:  
[https://github.com/fonsp/Pluto.jl/wiki/🎁-Package-management](https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management)

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [July 26, 2021, 4:04pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/3 "2021-07-26T16:04:24Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![amit1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amit1/32/25318_2.png) [@amit1](https://discourse.julialang.org/u/amit1)\
**Post date:** [July 26, 2021, 4:12pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/4 "2021-07-26T16:12:48Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [July 26, 2021, 4:18pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/5 "2021-07-26T16:18:11Z")

</div>

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: [https://github.com/fonsp/Pluto.jl/wiki/🎁-Package-management#pattern-the-shared-environment](https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management#pattern-the-shared-environment)  
Combining both approaches is not possible because it would be ambiguous.

---

<div class="post-metadata">

**Author:** ![CGenie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgenie/32/23819_2.png) [@CGenie](https://discourse.julialang.org/u/CGenie)\
**Post date:** [February 15, 2022, 9:41am UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/6 "2022-02-15T09:41:15Z")

</div>

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

```julia
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

```julia
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.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [February 15, 2022, 1:25pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/7 "2022-02-15T13:25:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [February 15, 2022, 2:12pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/8 "2022-02-15T14:12:04Z")

</div>

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

```julia
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!

> [@Pluto not respecting project environment](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/5):
>
> 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: [https://github.com/fonsp/Pluto.jl/wiki/gift-Package-management#pattern-the-shared-environment](https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management#pattern-the-shared-environment) Combining both approaches is not possible because it would be ambiguous.

---

<div class="post-metadata">

**Author:** ![CGenie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgenie/32/23819_2.png) [@CGenie](https://discourse.julialang.org/u/CGenie)\
**Post date:** [February 16, 2022, 5:06am UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/9 "2022-02-16T05:06:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [February 16, 2022, 4:01pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/10 "2022-02-16T16:01:17Z")

</div>

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

```julia
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:

 ![Screenshot from 2022-02-16 10-49-32](https://global.discourse-cdn.com/julialang/original/3X/4/c/4cde5a9a0dacd63f497b16c0f09661e78e543721.png)

Here’s the [corresponding repo](https://github.com/icweaver/Db.jl) for it, just to make sure I am on the same page as you

---

<div class="post-metadata">

**Author:** ![CGenie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgenie/32/23819_2.png) [@CGenie](https://discourse.julialang.org/u/CGenie)\
**Post date:** [February 16, 2022, 7:41pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/11 "2022-02-16T19:41:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CGenie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgenie/32/23819_2.png) [@CGenie](https://discourse.julialang.org/u/CGenie)\
**Post date:** [February 16, 2022, 7:57pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/12 "2022-02-16T19:57:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CGenie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgenie/32/23819_2.png) [@CGenie](https://discourse.julialang.org/u/CGenie)\
**Post date:** [February 16, 2022, 8:25pm UTC](https://discourse.julialang.org/t/pluto-not-respecting-project-environment/65308/13 "2022-02-16T20:25:58Z")

</div>

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