fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.92k stars 284 forks source link

Pluto doesn't use Pkg environments? #393

Closed limzy12 closed 3 years ago

limzy12 commented 3 years ago

I have an environment setup and activated with my dependencies and have the Pluto notebook in the same folder. However, Pluto does not seem to detect the installed dependencies in the environment?

Then when I run import Pkg; Pkg.add("PlutoUI") in a cell, the global Project.toml and Manifest.toml at .julia/environments/v1.5 get updated instead of those in the environment. Is this expected behaviour?

shashankp commented 3 years ago

Need to explicitly create a new env using Pkg.activate command

repl screenshot

limzy12 commented 3 years ago

I usually activate the environment via ] activate . . So in this case I should run import Pkg; Pkg.activate(".") in a cell in Pluto?

grero commented 3 years ago

That's what I usually do, and it's working great for me : )

fonsp commented 3 years ago

@Roger-luo is working on making this experience better, see https://github.com/fonsp/Pluto.jl/pull/341 and linked discussions

limzy12 commented 3 years ago

@fonsp Read the discussions and saw that Pluto has been updated with the functionality. But still not too sure on how to use it. Any advice?

Roger-luo commented 3 years ago

I think to make things more smooth we need #367 and #366 so there will be some breaking changes on this. But for now, just FYI, @limzy12 you can check: https://github.com/fonsp/Pluto.jl/pull/396#issuecomment-689761594

Eventually, I'm thinking about providing a simpler access to open pluto in terminal directly as

pluto --project=<your project path>

and it starts with --project=@. by default.

dlfivefifty commented 3 years ago

You can also do:

pkg"activate ."

in a cell

fonsp commented 3 years ago

But note that Pluto will always run cells that use using or import before cells that don't. This means that you can't use pkg"..." to set up a notebook environment, because it runs after your imports.

See https://github.com/fonsp/Pluto.jl/issues/142#issuecomment-685135043 for the recommended method.

dlfivefifty commented 3 years ago

That seems like very arbitrary behaviour...why not just execute in order?

dralletje commented 3 years ago

@dlfivefifty because we can't find out the right order for cells with using ..., as we only use static analysis on the cells - we don't look at the environment, the packages, the exported names from the package. Mostly because we don't want to run code before being able to determine the cell order, and we do need to actually run a modules Julia files to find the exports.

This is something that we can't really easily fix, but yeah running the cells first does feel kinda hacky

dlfivefifty commented 3 years ago

Maybe add pkg"..." cells to the priority list?

dralletje commented 3 years ago

Yeah that's something we can do, although we are looking a for a more systemic solution - the current way, even with pkg"" prioritized, is too confusing.

You can make a pull request with pkg added to the list and we will see what we can do. If you have thoughts on how to make this work nice, reproducible and predictable by default, that would be an amazing addition #142

dlfivefifty commented 3 years ago

I think Mathematica is the gold standard for notebooks.. I'd love it to work like that. but it seems like you are going a very different direction in terms of reactivity so I'm not sure what your plan is.. for example the not being able to have multiple lines in a cell or redefine variables is very strange to me.

fonsp commented 3 years ago

Just to be clear:

Current solution

Use Pkg.activate. You need to do everything in one cell to enforce that they run linearly:

begin
    import Pkg
    Pkg.activate(".")
    using A
    using B
    using C
end

Future solution

142