Skip to content

Commit e3e299e

Browse files
authored
use _set_conda_env to launch jupyter (#900)
1 parent a5511cb commit e3e299e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/jupyter.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@ function find_jupyter_subcommand(subcommand::AbstractString)
1717
jupyter = joinpath(Conda.SCRIPTDIR, exe("jupyter"))
1818
end
1919
end
20+
isconda = dirname(jupyter) == abspath(Conda.SCRIPTDIR)
2021
if !Sys.isexecutable(jupyter)
21-
if dirname(jupyter) == abspath(Conda.SCRIPTDIR) &&
22-
isyes(Base.prompt("install Jupyter via Conda, y/n? [y]"))
22+
if isconda && isyes(Base.prompt("install Jupyter via Conda, y/n? [y]"))
2323
Conda.add(subcommand == "lab" ? "jupyterlab" : "jupyter")
2424
else
2525
error("$jupyter is not installed, cannot run $subcommand")
2626
end
2727
end
2828

29+
cmd = `$jupyter $subcommand`
30+
2931
# fails in Windows if jupyter directory is not in PATH (jupyter/jupyter_core#62)
30-
env = Sys.iswindows() ? Dict(uppercase(k)=>v for (k,v) in ENV) : copy(ENV) # julia#29334
3132
pathsep = Sys.iswindows() ? ';' : ':'
32-
env["PATH"] = haskey(env, "PATH") ? dirname(jupyter) * pathsep * env["PATH"] : dirname(jupyter)
33+
withenv("PATH" => dirname(jupyter) * pathsep * get(ENV, "PATH", "")) do
34+
if isconda
35+
# sets PATH and other environment variables for Julia's Conda environment
36+
cmd = Conda._set_conda_env(cmd)
37+
else
38+
setenv(cmd, ENV)
39+
end
40+
end
3341

34-
return setenv(`$jupyter $subcommand`, env)
42+
return cmd
3543
end
3644

3745
##################################################################

0 commit comments

Comments
 (0)