8

EDIT on 27 Aug 2016: Used bash -c in exec line, error message gone but jupyter not starting. Is this even possible on Ubuntu? seems like a lot of effort to implement a simple functionality.

EDIT on 16 Aug 2016: Replaced the ~ with $HOME, but error message persists.

I'm on Ubuntu 16.04 and I'm trying to create a script on the desktop that would start jupyter notebook from a certain directory, say ~/Notebook.

I know how to make it work in terminal, just run jupyter notebook --notebook-dir=~/Notebook, then I'm on my way.

But how to make an icon on the desktop and when I double-click it, it just run that command?

There must be something obvious I'm missing here.

[Desktop Entry]
Version=1.0
Name=Jupyter
Comment=Jupyter Desktop Shortcut
Exec=jupyter notebook --notebook-dir=~/Notebook
Path=~/Notebook
Terminal=true
Type=Application
Icon=~/Downloads/7388996.png

it just reported "There was an error launching the application."

Where should I go from here?

Thanks!

8
  • 2
    Try replacing ~ by $HOME: see Home directory paths in Unity Launcher Aug 14 '16 at 3:17
  • Many thanks! Will try it out at home and report back!
    – PaulDong
    Aug 15 '16 at 6:16
  • Sorry to report that I've replaced the ~/ with $HOME/, but the error message didn't change. But thanks for the help anyway.
    – PaulDong
    Aug 16 '16 at 14:32
  • In that case you may just have to use the full absolute path Aug 16 '16 at 17:54
  • Absolute path is the next thing I tried, and the icon line definitely worked, but the program itself still refuse to start, no change in error message.
    – PaulDong
    Aug 17 '16 at 15:08
6

I would suggest you use bash for the Exec key. Try bash -c "~/anaconda2/bin/jupyter notebook --notebook-dir=~/Notebook", or bash -i -c "jupyter notebook --notebook-dir=~/Notebook if you have added the full path to the environmental variables.

Not sure why your entry wouldn't work, but I guess it might be the before "notebook"?

BTW, I wouldn't use a desktop entry for applications like Jupyter Notebook, as I reckon the notebook process still needs to be killed in terminal.

9
  • Many thanks! I'm learning Ubuntu and I sort of modeled the desktop entry as an windows shortcut, but they are clearly different animals. I tried the bash -c command and no error message showed up, but the jupyter notebook was not starting either - I only saw an icon on the task bar, stayed for 5-10 seconds before disappearing again. Now if i just want something to start by click / double-click without error-prone terminal typing, what is the best way to do it in Ubuntu 16.04?
    – PaulDong
    Aug 25 '16 at 5:31
  • @PaulDong My bad. The command was auto corrected as "Jupiter". Try the new command with "jupyter". You could also try it in terminal where you could see bash's debugging info. I really don't know what's the solution to your last question and I'm actually used to terminal typing. I'd appreciate it if you could share it with me once you find it ;) Aug 25 '16 at 6:07
  • Many thanks! Sorry for not making it clear I did understood the jup[i]yter autocorrect. I shall try it on terminal and see the error message tonight.
    – PaulDong
    Aug 26 '16 at 2:07
  • Tried it on the terminal and it worked like a charm. But when I double-click the revised desktop file, there were an additional icon on the launcher bar for a few seconds before it was gone. No jupyter tab open in the browser. Tried double and single quote.
    – PaulDong
    Aug 27 '16 at 0:36
  • If it is not possible to create an icon to launch jupyter in Ubuntu, is there anyway to shorten the line I have to type in the terminal? typing the line was a bit distracting. can I just type jn in the terminal and it just execute the above jupyter notebook --notebook-dir=~/Notebook? Any reference I can learn how to do that would be helpful. Thanks!
    – PaulDong
    Aug 27 '16 at 0:48
1

I was using:

Exec=/home/paul/anaconda3/bin/jupyter notebook --notebook-dir=~/Notebook

As suggested in a comment by PaulDong, but I was having problems trying to add a path to the PYTHONPATH.

Now I am using the following (on Ubuntu 16.04):

I have created a jupyter_.sh (in /home/usr/) file with the following:

#!/bin/bash     

# OPTIONAL - add to PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/path_to_add/

# start notebook at the desired folder
jupyter notebook --notebook-dir '/path_to_notebooks/'

And I have a Jupyter.desktop file with:

[Desktop Entry]
Version=1
Name=Jupyter
Comment=Open jupyter at different dir
Exec=bash -c "~/jupyter_.sh"
Icon=/home/usr/anaconda3/lib/python3.5/site-packages/anaconda_navigator/static/images/jupyter-icon-1024x1024.png
Terminal=true
Type=Application
0

Try writing a simple shell script (with your command), and make it executable (using 'chmod +x'), then use this in the exec field.

3
  • Many thanks, a newbie here, is there any good reference / guide I can learn to write that script and after I made the script 'jupyter.sh" executable, where should I save it and what to put in the exec line?
    – PaulDong
    Aug 27 '16 at 0:44
  • Before doing that, try some changes in your existing.desktop entry. First, instead of a true in the Terminal field, use false. Second root should be the owner of this desktop file. So using sudo create one through terminal (sudo gedit your-file). And then move that file to /usr/share/applications (sudo mv your-file /usr/share/applications).
    – Rpal
    Aug 27 '16 at 3:45
  • Many thanks Ritesh! user5206460's answer did the trick. Maybe this is a bit controversial, but with terminal=true, I could kill the running process after I'm done. Also while I do see the benefit of moving it to the application folder (it can then be access via unity launcher), the icon on desktop was gone. so I ended up only copying it there.
    – PaulDong
    Aug 28 '16 at 1:12
0
sudo apt install xterm
/usr/bin/xterm -geometry 200x20+0+0 -e jupyter notebook

See xterm manual for options. The above command can be used in the exec line in the launcher

0

Currently working with Ubuntu 19.10 and Anaconda 3.

It also doesn't open up a terminal window which is nice.

cd /usr/share/applications
sudo nano Jupyter.desktop

Replace 'jake' and the path as necessary

[Desktop Entry]
Version=1.0
Type=Application
Name=jupyter-notebook
GenericName=Jupyter
Comment=Scientific Python Development Environment - Python3
Exec=bash -c 'export PATH="/home/jake/anaconda3/bin:$PATH" && /home/jake/anaconda3/bin/jupyter-notebook'
Categories=Development;Science;IDE;Qt;Education;
Icon=/home/jake/anaconda3/lib/python3.7/site-packages/anaconda_navigator/static/images/jupyter-icon-1024x1024.png
Terminal=false
StartupNotify=true
MimeType=text/x-python;

After that you should be able to find it in the applications.

0
:~$ jupyter-notebook
:~$ sudo micro /home/<username>/.local/share/applications/jupyter-notebook.desktop
 [Desktop Entry]
Name=Jupyter Notebook
Comment=Run Jupyter Notebook
Exec=jupyter-notebook
Icon=jupyter-notebook
Type=Application
Categories=Development;Education
StartupNotify=true
StartupWMClass=jupyter-notebook
Actions=open-browser
:~$ jupyter-lab
:~$ sudo micro /home/<username>/.local/share/applications/jupyter-lab.desktop
 [Desktop Entry]
Name=Jupyter Lab
Comment=Run Jupyter Lab
Exec=jupyter-lab
Icon=jupyter-lab
Type=Application
Categories=Development;Education
StartupNotify=true
StartupWMClass=jupyter-lab
Actions=open-browser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.