Why the Project Activated in Jupyter Notebook Does Not Change?

Hi all,

I know to start a new clean environment / project is by typing this in a terminal:

julia --project="."

So when I do that in different folder and check with:

julia> ]

pkg> st

the packages will be different for different folders.

The bugging / disturbing thing is, I use Jupyter Notebook, and it cannot detect the environment that I call to open IJulia / Jupyter Notebook.

I have installed lots of packages in LasthrimProjection folder (intended for Mathematics) thus I create new folder named FreyaLab (for Electrical Engineering), but when I start IJulia from FreyaLab and check with ]st it still detecting or using LasthrimProjection environment.

How to change this to FreyaLab? So I can install packages related to Electrical Engineering only while using Jupyter Notebook / IJulia.

This is a technical question. Thanks all

How to change this to FreyaLab?

You ensure that you have “a project” in FreyaLab, with files Project.toml and Manifest.toml.

Try, in your notebook, Pkg.activate("."), and then add some packages to the new environment.

After that, any notebook that you open in that folder should use the folder as its environment.

1 Like

You might want to take a look at this guide on Pkg which does a great job on explaining the usage of it: jkrumbiegel.com - Pkg.jl and Julia Environments for Beginners

1 Like

To my understanding, the original environment from which you start notebook() doesn’t matter, and isn’t used by Jupyter. Jupyter starts its own Julia process, based on the Julia kernel you select.

You can explicitly do

import Pkg
Pkg.activate("~/FreyaLab")

in a cell at the beginning of the notebook to get the notebook to activate that environment.

You can also create a different Jupyter kernel specifically for this project, if this is something you do all the time, but it’s probably overkill if you only need it for this one notebook.

2 Likes

If you do need this, you can do

using IJulia
installkernel("Julia FreyaLab", "--project=~/FreyaLab")

just once to add a specific Jupyter kernel for this project. Once you do this, “Julia FreyaLab” will be an additional option to choose in the Jupyter kernels menu.

So anytime after that, you can choose that kernel as the one to run in the Jupyter dropdown menu.

4 Likes

This works greatly. I can adjust the path to the designated folder.

Given the folder has its own Project.toml and Manifest.toml