JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.78k stars 409 forks source link

Specify an environment containing IJulia *only* when started via kernel #1059

Open pdeffebach opened 1 year ago

pdeffebach commented 1 year ago

My understanding is that currently, as long as Julia is listed on the kernel file, you can do

jupyer lab --kernel=julia-1.8

but if your Julia 1.8 environment doesn't have IJulia, the kernel will hang / throw an error.

Would it be possible to push! an environment contiaining only IJulia to the LOAD_PATH when Julia is started via the kernel? This could be done in the kernel initialization script, right?

I understand that pushing to LOAD_PATH is generally not recommended. Perhaps there is a way to do this with stacked environments as well.

fortunewalla commented 1 year ago

I don't know if this will help you but in the your jupyter kernels folder, and in that, within that in the julia-1.8 folder, there is a file called kernel.json.

For WIndows: C:\Users\<username>\AppData\Roaming\jupyter\kernels\julia-1.8\kernel.json

So if you want jupyter to use the IJulia installed in juljup environment

Just change the --project path to make jupyter start from the juljup environment

original kernel.json

{
  "display_name": "Julia 1.8.3",
  "argv": [
    "C:\\julia\\bin\\julia.exe",
    "-i",
    "--color=yes",
    "--project=@.",
    "C:\\julia\\.julia\\packages\\IJulia\\AQu2H\\src\\kernel.jl",
    "{connection_file}"
  ],
  "language": "julia",
  "env": {},
  "interrupt_mode": "message"
}

modified --project to use IJulia from the juljup environment only

{
  "display_name": "Julia 1.8.3",
  "argv": [
    "C:\\julia\\bin\\julia.exe",
    "-i",
    "--color=yes",
    "--project=juljup",
    "C:\\julia\\.julia\\packages\\IJulia\\AQu2H\\src\\kernel.jl",
    "{connection_file}"
  ],
  "language": "julia",
  "env": {},
  "interrupt_mode": "message"
}

Hope this helps in some way.

pdeffebach commented 1 year ago

Wonderful! This works, thanks.

Would be great if this were a default somehow, given its not great to clutter your global project.

fortunewalla commented 1 year ago

Wonderful! This works, thanks.

Would be great if this were a default somehow, given its not great to clutter your global project.

I'm a beginner in Julia but for some reason, it won't work even if the default project path is specified in the OS Environment; as juljup. i.e. JULIA_PROJECT=c:\julia\juljup

I suspect it has to do with the stage when IJulia creates the kernel. Perhaps it doesn't read the project environment but installs the kernal using the default Julia path.