I am trying to run a Jupyter notebook (and a project in general) in a specific environment with only a limited number of packages.
I have created a folder. In my terminal, I navigated to this folder, started julia, and ran ]activate .. I then added a few packages ]add DifferentialEquations, Plots. Next I started jupyter, and created a Jupyter notebook in the same folder (in which there now is a Manifest.toml and a Project.toml file). I start the Jupyter notebook. However, this Jupyter notebook have access to a lot of other packages more than jus DifferentialEquations and Plots (packages which I have added to my main environment).
I have tried running using Pkg; Pkg.activate() in the Jupyter notebook, but didn’t work.
If I run pwd() in the Jupyter notebook it returns the path to the place where the jupyter notebook and the 2 toml files are (if I understood the question right?).
I see, yes if I do Base.load_path() things points somewhere else.
However, how would I do to set a more limited scope? Typically I have just run everything in the main one, but if I understand things right the recommended approach is to have a specific environment for every project (?). The idea is to prepare some files and code, so that someone else then could re-run the project in the same environment using that file.
(also, the main environment is a mess, and I can’t really update it anymore because various incompatibilities starts to appear)
So, I tried to run this in my Jupyter Notebook, but the result seems to be that my load path is empty? I can’t run using on any package (even those I tried to add to this environment). Also, Base.load_path() returns String[].
For example, starting jupyter with JULIA_LOAD_PATH="@:@stdlib" jupyter-notebook should do it.
If I add this thing, would it make Jupyter default loading any environment with toml files in the folder of the notebook? Also, would I need to to start jupyter from that specific folder, or could I have one jupyter program open, with several notebooks open in various folders, in various projects, in various environments?
So I did a bit of testing. If I create a new notebook in that folder, and then run
using Pkg
Pkg,status()
to check my environment, then if I create the notebook in Julia 1.5.2 I am in the local environment. However, if I do the same in Julia 1.6.1, it doesn’t seem to work. I am not sure why, but if there would be some way to resume the Julia 1.5.2 behaviour, that would be great!
That’s the default behavior without any extra config.
The second one: JULIA_LOAD_PATH="@:@stdlib" is passed to each Julia instance, started for each notebook. Each of these Julia instances will interpret @ and @stdlib “locally”. Unless I’m mistaken of course
Note that the Julia default is equivalent to JULIA_LOAD_PATH="@:@v#.#:@stdlib". This means that Julia will load packages from the local project (@), from the global user environment (@v#.#) and from the Julia installation (@stdlib). All we’re doing is removing the @v#.#.