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

- 10,413
- 1
- 32
- 47
-
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. – Lewis Levin Aug 29 '22 at 18:26
You can always start up a notebook, and within a cell run
using Pkg
Pkg.activate("./path/to/folder")

- 1,274
- 11
- 22
-
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? – Lewis Levin Aug 29 '22 at 19:27
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.

- 40,002
- 3
- 32
- 62
-
-
1No, 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: https://github.com/crstnbr/JuliaOulu20 – carstenbauer Feb 28 '20 at 09:20
-
1Also, just take a look at the implementation: https://github.com/JuliaLang/IJulia.jl/blob/bd9b39e27e0c41ebd8aa8d5d0a6ed5388924e439/deps/build.jl#L5 – carstenbauer Feb 28 '20 at 09:21
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.

- 369
- 1
- 13