# Weird Sys.which() function

**URL:** https://discourse.julialang.org/t/weird-sys-which-function/58070
**Category:** General Usage
**Tags:** ijulia
**Created:** [March 27, 2021, 10:31am UTC](https://discourse.julialang.org/t/weird-sys-which-function/58070 "2021-03-27T10:31:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)
#### Post date: [March 27, 2021, 10:31am UTC](https://discourse.julialang.org/t/weird-sys-which-function/58070/1 "2021-03-27T10:31:15Z")

</div>

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
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:

```julia
[~]which jupyter
/snap/bin/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 `//github.com/JuliaLang/IJulia.jl` shows:

```julia
function find_jupyter_subcommand(subcommand::AbstractString)
    [...]
    jupyter = Sys.which(exe("jupyter"))
    [...]
end

```

and returning to the REPL I got the bad answer:

```julia
julia> Sys.which("jupyter")
"/usr/bin/snap"

```

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](https://discourse.julialang.org/t/need-help-with-ijulia-on-ubuntu-18-04-5-lts/49118)), snap has been standard for some years.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [March 27, 2021, 12:22pm UTC](https://discourse.julialang.org/t/weird-sys-which-function/58070/2 "2021-03-27T12:22:13Z")

</div>

> [@j2b2](#):
>
> The lesson of this story is that the julia function `Sys.which()` should not return another path than the (very useful) linux command `which` .

But the very useful linux command `which` may or may not be available on all platforms: [Search path for executable](https://discourse.julialang.org/t/search-path-for-executable/3511). `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?

---

<div class="post-metadata">

### Author: ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)
#### Post date: [March 27, 2021, 1:16pm UTC](https://discourse.julialang.org/t/weird-sys-which-function/58070/3 "2021-03-27T13:16:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [March 27, 2021, 2:53pm UTC](https://discourse.julialang.org/t/weird-sys-which-function/58070/4 "2021-03-27T14:53:43Z")

</div>

[https://github.com/JuliaLang/julia/pull/40233](https://github.com/JuliaLang/julia/pull/40233)
