Weird Sys.which() function

Hi, IJulia doesn’t work on my system, Ubuntu LTS 20.04. The (bash) command jupyter notebook works fine, but I don’t see julia when I press the “new” button. So I launched julia REPL and tried :

julia> using IJulia

julia> notebook()
[ Info: running `/usr/bin/snap notebook`
Process(setenv(`/usr/bin/snap notebook`; dir="/home/betrema"), ProcessExited(64))

Why the hell does jupyter disappear from this short log? The answer looks simple, let us return to bash:

[~]which jupyter
[~]ls -l /snap/bin/jupyter
lrwxrwxrwx 1 root root 13 mars  23 17:01 /snap/bin/jupyter -> /usr/bin/snap

and yet the two commands (source and target of the link) give different results with argument notebook! This situation left me wondering, until I thought of the argument argv[0] of a C program, that is the name of the command, and some testing confirmed that this name is different when we use a link. Here usr/bin/snap is a kind of dispatcher among snap packages, using name of the link “source”.

Some investigation on // shows:

function find_jupyter_subcommand(subcommand::AbstractString)
    jupyter = Sys.which(exe("jupyter"))

and returning to the REPL I got the bad answer:

julia> Sys.which("jupyter")

The code of the function Sys.which() uses the function realpath(), that canonicalize a path by expanding symbolic links […]

The lesson of this story is that the julia function Sys.which() should not return another path than the (very useful) linux command which.

PS Please, don’t tell me to install jupyter with another package manager (as in the post Need Help with IJulia on Ubuntu 18.04.5 LTS), snap has been standard for some years.

But the very useful linux command which may or may not be available on all platforms: Search path for executable. Sys.which is meant to be a platform-independent alternative, otherwise one can just do run(`which`).

That said, not using realpath is probably reasonable. Do you mind opening a pull request to fix that?

1 Like

I agree. I can open an issue, but not a pull request, sorry, I’m an old man not used to these development tools :frowning: