Open specific jupyter notebook from terminal - terminal

Is it possible to open a specific Jupiter notebook from terminal.
The file -> open -> search for it is time consuming 🙈

This may depend how what operating system you are using (or environment such as anaconda), but in general I think this should work:
jupyter notebook notebook.ipynb
...where notebook.ipynb is the notebook you want to open, see here.

Once the server is running, you can open using this url
http(s)://server:port//lab/tree/path/to/notebook.ipynb
https://jupyterlab.readthedocs.io/en/stable/user/urls.html#url-combine

Related

Jupyter Lab shows last used folder as the root directory when run from terminal (can't go up), but it's ok when run from Anaconda

I've been using Anaconda and Jupyter Lab & Notebook for a couple of months. I have 4 environments and had the usual problems I guess everyone has with package conflicts and such.
Today, when I was running a ipynb file in Jupyter Lab (run from Terminal), it got stuck when iterating over files and unzipping them, so I rebooted my Mac.
When I entered Jupyter Lab again, the folder it showed in the file browser was the last one I had used. It didn't have the option of going up, and if I entered a path in "open from path", it said that it couldn't find it. It's like the last folder I used is now considered the root path.
I tried running Jupyter Lab again from terminal, but same thing.
Of course, other environments weren't affected.
I thought it was a Jupyter Lab configuration problem, but when I run Jupyter Lab from Anaconda, it went back to working perfectly, so I'm wondering if there is a configuration setup specifically for Terminal.
I can work from Anaconda, and I can also reinstall the environment if needed, but I'd prefer to go back working the way I was.
Jupyter Notebook works fine.
Can anyone shed a light on what can be happening?
Thanks!
I tried:
reboot the computer
exit and reenter Jupyter Lab
go to "open from path"
search for jupyter config file with "jupyter --config-dir". Found "default-37a8.jupyterlab-workspace" in the /User/.jupyer/lab/workspaces folder, and it has the initial config for Jupyter Lab (directory, files opened), but it takes the info from when I close the instance I run from Anaconda. When run from terminal it's like it takes the initial config from somewhere else.

Can't open Jupyter notebook from command prompt

I have always opened the jupyter notebooks from the Anaconda prompt. The problem is that whenever I try to open the Jupyter notebook from the command prompt, the following error is displayed:
Picture of the Error shown on my command prompt window
ImportError: DLL load failed: The specified module could not be found.
What am I doing wrong ? What should I do?
Opening Jupyter Notebook from command prompt is useful, especially when you would like to open the Jupyter Notebook from a specific folder.
The following 2 steps might help you to resolve this issue.
open command prompt
activate base
The prompt might change to begin with "(base)", which is expected. Then type,
Jupyter-notebook
If Jupyter notebook opens up now, this means Jupyter is correctly installed within your conda environment. In OS like Windows 10, it was an expected behavior not to recognize Python outside of Conda environment, which extends to Jupyter Notebook as well.
If the 1st step works properly, then add the below paths to your
environment variable. If you would not like to add the path to your
system environment variable, you can choose to update in your
account environment variable.
In windows 10 >> search "environments" and "Edit environment
variables for your account"
Select "PATH" and edit.
Add below paths
C:\Users\\Anaconda3;
C:\Users\\Anaconda3\Scripts;
C:\Users\\Anaconda3\Lib;
C:\Users\\Anaconda3\Library\bin;
C:\Users\\Anaconda3\Library\mingw-w64\bin;
Now you should be able to open Jupyter Notebook directly from command prompt.

Associate ipynb files with Jupyter notebook in Windows 10 (Anaconda)

I installed Anaconda on my Windows 10 machine.
I have a few Jupyter notebooks on my pc and I would like to associate them with Jupyter, so they can be opened by double-clicking on the file, to avoid having to open Jupyter and navigate to the notebooks folders each time. Is this possible?
All notebooks should open in the same Jupiter Kernel (same localhost in the browser address bar), without starting a new kernel for every file I click.
PS I asked here because I figured this question to be more of interest for programmers, but if you think it would be more suited for SuperUser, I'll flag it for migration.
Install nbopen: https://github.com/takluyver/nbopen
pip install nbopen
python -m nbopen.install_win
Now you can double-click on *.ipynb files:
If you have Jupyter installed with Anaconda you can do the following.
Create a little batch file (e.g. start_jupyter_notebook.bat) with the content (the commands are from the Jupyter shortcut):
#echo off
set ANACONDAPATH=C:\_work\_programs\Anaconda3
%ANACONDAPATH%\python.exe %ANACONDAPATH%\cwp.py %ANACONDAPATH%^
%ANACONDAPATH%\python.exe %ANACONDAPATH%\Scripts\jupyter-notebook-script.py %1
(of course you will have to change the ANACONDAPATH to your installation)
Then go to one .ipynb file of your choice, right-click on it, go to properties --> open with --> change and select your created batch file.
I am pretty sure this can also be setup for any other Python/Jupyter installation.
P.S. The cwp.py file sets up some environment variables. I guess this is the reason why fredm73's answer did not work for everybody. Apart from that my answer is quite similar in the end.
associate .ipnyb with jupyter-notebook.exe
On Windows 10: control panel/Programs/Default Programs/Associate a file type or protocol with a program/Choose default apps by file type
Look at the list of extensions, find '.ipnyb'. Click on icon and locate the jupyter notebook program. In my Anaconda installation, it is found at
anaconda/scripts/jupyter-notebook.exe
Easiest way for me - double click on the .ipnyb file. When prompted to pick a program to open the extension with go to /ProgramData/Anaconda3/Scripts and locate the jupyter-notebook.exe file and click it.
NOTE - to access the ProgramData folder you will need to view hidden folders in the Windows explorer or access it by typing %programdata% in the navigation line:
You can use nbopen on pip and run the module:
py -m pip install -U nbopen
py -m nbopen.install_win
For those who installed nbopen in Anaconda but it does not work:
Use Regedit to search for a directory called Jupyter.nbopen, and navigate to its shell\open\command. It should be something like:
HKEY_USERS\****\Software\Classes\Jupyter.nbopen\shell\open\command
Then, change the default to: (Modify the path if you are not installed in default location)
"C:\ProgramData\Anaconda3\pythonw.exe" "C:\ProgramData\Anaconda3\cwp.py" "C:\ProgramData\Anaconda3" "C:\ProgramData\Anaconda3\pythonw.exe" -m nbopen "%1"
The reason behind this is that cwp.py makes sure that the Jupyter is running in Anaconda instead of other Python environments.
Then it should work, although it will activate two invisible pythonw process running in the background.
Just look into your file directory and look for programs that can open the file type and set it as your default app opener but you need to take into consideration that if you want to use Jupiter notebook, you can run jupyternotebook app and locate the file from the jupyter notebook directory.
Secondly, ensure you have added your python.eex to path and run directly from your command prompt. See pictures in the screenshot
Find the jupter-notebook.exe in the C:\Users\my_username\Anaconda3\Scripts folder. Copy the address. When you're opening the .ipnyb file double click ( if first time) or just do open with and there in the menu you can tick the 'always use this' option and locate the notebook from 'look more programs' option in the menu.

Open new named jupyter notebook from terminal

I can open an existing jupyter notebook with a single command (from the docs):
When starting a notebook server from the command line, you can also open a particular notebook directly, bypassing the dashboard, with ipython notebook my_notebook.ipynb. The .ipynb extension is assumed if no extension is given.
However, when I want to open a new notebook it seems as if I have to follow 3 steps:
Run ipython notebook.
Open a new notebook by clicking New > Python 3.
Edit the name of the notebook
Question
Is there a command that allows me to combine these 3 steps in a single command, similar to the command to open existing notebooks? E.g., something like this pseudo code: ipython notebook --new my_notebook.ipynb.
Using this command you can create and open a new notebook without getting into the application. This command will work only in Linux operating system
jupyter notebook $(cat Untitled.ipynb >filename.ipynb && echo filename.ipynb)

Is it possible to navigate to a parent directory in the jupyter tree?

Normally, I launch jupyter from a new bash terminal:
~$ jupyter notebook
and then navigate down the tree to the files I want to work at.
I just did it from a terminal that was already running at a different path:
~/blah/blah/blah$ jupyter notebook
and realized that that directory becomes the home for jupyter. I wanted to work at a file located at, say ~/blah/thingy/luis.ipynb, but couldn't find my way up.
How do I navigate the directory tree upwards in jupyter notebook?
As explained in https://github.com/ipython/ipython/issues/7751, it is not possible to navigate to the parent directory for security reasons:
The kernel might not be python, nor on the same machine than the
server, nor do you need a running kernel to use server API(s).
If you want, you can ask for more information in the aforementioned GitHub issue.
As edwinksl pointed out it is not possible for security reasons. See https://github.com/jupyter/notebook/issues/2032.
But if you want to keep your luis.ipynb file in its original location and still be able to access it from Jupyter Notebook browser, you can create a symlink to it in your running Jupyter Notebook directory:
ln -s ~/blah/thingy/luis.ipynb ~/blah/blah/blah/
For more details on symlinks see https://www.howtogeek.com/297721/how-to-create-and-use-symbolic-links-aka-symlinks-on-a-mac/

Resources