8

I am encountering package compatibility issues within my global Julia environment for specific packages I want to use in a Jupyter notebook. Is there a way to tell IJulia to use a different environment instead of my global one?

4 Answers 4

18

The default IJulia kernel sets --project=@. so the most convenient way (IMO) is to just keep your project in the same folder as the notebook. The result is that the correct project is used from the start and you don't have to worry about activating it while in the notebook.

Sign up to request clarification or add additional context in comments.

1 Comment

So many problems... What if the notebook is in a subdirectory of the project? What if the project and notebook are in completely different directories? Why can't we make the environment of the kernel associated with the Julia version used by the kernel--this last makes the most sense.
10

You can always start up a notebook, and within a cell run

using Pkg Pkg.activate("./path/to/folder") 

1 Comment

Of course. This is the most explicit. Problem is that if you switch kernels you have to change the string argument to package activate. Can this be an environment variable or other parameter of the kernel itself--as it should be?
6

When starting the notebook type:

notebook(dir="/path/to/your/environment/") 

This will launch Jupyter notebook loading the environment (Project.toml) in the directory that you have specified. If there is no Project.toml in that directory, the default (global) environment will be used.

3 Comments

This is just a consequence of @fredrikekres answer isn't it?
No, his answer is perfectly correct. If you create an ipynb and a Project.toml in the same folder the ipynb will load this Project.toml. I utilize this all the time for example in my workshop where there are different environments in some of the subfolders: github.com/crstnbr/JuliaOulu20
Also, just take a look at the implementation: github.com/JuliaLang/IJulia.jl/blob/…
-1

Depending on the complexity of your setup, you might want to consider Lmod I use this with a module hierarchy: 1. Core module, 2. Compiler modules, MPI modules. With this, its possible to quickly switch between difference branches.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.