Open new named jupyter notebook from terminal - 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)

Related

Does jupyter lab work within its own conda environment it was installed in?

I have multiple conda environments on my PC created with Anaconda and I have installed jupyterlab in two of them. I used one environment for R programming and the other for Tensorflow with Python. I have noticed that whenever I open jupyter lab in either of the environments, it always starts off where I left it. That is, the last open notebooks are opened on start. Of course, this doesn't bother me too much, but it makes me think each jupyter lab installation isn't contained within its own environment.
For example, I have two environments. Say they're called env_R and env_Python_TF. I have installed jupyter lab in both environments.
I open Anaconda Powershell prompt and launch each environment using the following commands:
(base) PS $ conda activate env_R
(env_R)PS $ jupyter lab
Say I work on jupyter lab and once I'm done, I close the browser windows and then shut down the server using CTRL+C in Anaconda Powershell prompt. Now if I open up my second environment using:
(base) PS $ conda activate env_Python_TF
(env_Python_TF)PS $ jupyter lab
Now I see the same notebooks I used with env_R opened up when jupyter lab opens in my browser.
Aren't each jupyter lab installation contained within its own conda environments? If not, have I possibly made a mistake in my configuration?
it should be within its own conda environment but Default root folder /location will remain same for jupyter notebook. You will need to change it using config file.
Here is link

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.

Jupyter Notebook from Git Bash Here

I have Git for Windows and want to be able to start Jupyter Notebook in a directory of choosing using File Explorer. If I right click in a directory and select "Git Bash Here," a Bash shell opens. I already added my Anaconda directory (where my Python 3.7 is located) into the user path, and I can verify that Bash sees that in the path by "env|grep PATH". However, when I type "jupyter notebook" from the Bash prompt, it finds the script and it starts to run, but reports an "ImportError: DLL load failed: The specified module could not be found."
How do I set the Bash environment to start a Jupyter Notebook from the current directory where I have a Bash prompt?
I solve this problem with the command:
source "C:\Users\...\Anaconda3\Scripts\activate"
When you install Jupyter via anaconda it isn't added to the system's enviornment variables. Your system doesn't know about Jupyter. Only anaconda does because it is managing your packages and your versions for each project you create.
If you're using bash for windows I would think you'd have to install Jupyter notebooks to windows and add it to your environment variables to be able to see it in any directory.
Edit: Here's a picture of me running Jupyter from my windows command line and from the Anaconda prompt.
In your GitBash prompt type the following command
. Anaconda3/Scripts/activate
assuming you are in your home directory.
This will allow you to run jupyter from GitBash and also use UNIX commands from jupyter.

How to make jupyter start in current directory by default (in cmd.exe)?

In Windows 10 cmd.exe I can start jupyter in a current directory by following command:
jupyter notebook --notebook-dir="."
The current directory is C:\Users\Евгений\Documents\GitHub\sandbox
However, when I start simply jupyter notebook in a current directory above my working directory for jupyter is D:/git:
λ cd
C:\Users\Евгений\Documents\GitHub\sandbox
λ jupyter notebook
[I 14:46:44.273 NotebookApp] The port 8888 is already in use, trying another port.
[I 14:46:44.304 NotebookApp] JupyterLab beta preview extension loaded from D:\Anaconda3\lib\site-packages\jupyterlab
[I 14:46:44.304 NotebookApp] JupyterLab application directory is D:\Anaconda3\share\jupyter\lab
[I 14:46:44.571 NotebookApp] Serving notebooks from local directory: D:/git
Note the last line Serving notebooks from local directory: D:/git. Where is D:/git may be coming from? Are there environment variables other than these affecting working directory choice?
My %USERPROFILE%/.jupyter is totally empty.
jupyter --config-dir directs to C:\Users\Евгений\.jupyter, it is %USERPROFILE%/.jupyter.
I read various threads about jupyter invoke, in particular:
this large thread suggests jupyter notebook will behave differently in cmd.exe and Anaconda prompt, without further details though
Problems with configuring Jupyter start directory addresses an issue with Windows shortcut, similar to this Windows app start steps
this post proposes wrapping --notebook-dir="." key into a .bat file
My other thought is that %USERPROFILE% with non-Latin character is not be recongnisable by jupyter, but %USERPROFILE%/.jupyter is empty anyways.
You must generate the configuration of Jupyter.
jupyter notebook --generate-config
Navigate to your folder and the folder .jupyter (C:\Users\%username%\.jupyter)
You will find a file called jupyter_notebook_config.py
Edit it with notepad++ for exemple and locate c.NotebookApp.notebook_dir
Between ' ' put the path you want. For exemple :
c.NotebookApp.notebook_dir = 'C:/Users/Евгений/Documents/GitHub/sandbox'
Save it and start Jupyter without specifying a path
Be careful, the characters in your username may be a problem.
Keep me informed.
Use the jupyter notebook config file:
Open cmd (or Anaconda Prompt) and run jupyter notebook --generate-config.
This writes a file to C:\Users\username\.jupyter\jupyter_notebook_config.py.
Browse to the file location and open it in an Editor
Search for the following line in the file: #c.NotebookApp.notebook_dir = ''
Replace by c.NotebookApp.notebook_dir = 'D:/git'
Make sure you use forward slashes in your path
Remove the # at the beginning of the line to allow the line to execute
Using docker and the images maintained by the Jupyter team:
docker run -v `pwd`:/home/jovyan -p 8890:8888 jupyter/scipy-notebook

How to change Jupyter Notebook (Windows) shell to bash

I'm currently running Jupyter Notebook (Windows 7) within a Conda environment using Python 3.6.4 and my current version of Jupyter Notebook is 5.6.0. I came across the following article: Using Git Bash in Jupyter Notebook on Windows , that explains how to change the default shell within Jupyter Notebook to Bash by changing the config "C.NotebookApp.terminado_settings = {'shell_command': ['C:\Program Files\Git\bin\bash.exe']}. I've tried multiple different options for the path to bash, including just the name 'bash', with no success.
Python and Jupyter version:
Jupyter Notebook: Not changed, still using Powershell
I've read up on the Jupyter Notebook: Read the Docs , and made the changes to the jupyter_notebook_config.py found under C:\Users\UserName\.jupyter directory, without any success.
An alternative solution to your problem is to use the Windows Subsystem for Linux (WSL).
I am under Windows 10, conda 4.5.11 and Jupyter lab 0.35.3. I have also activated the Windows subsystem for Linux (WSL).
Using !wsl you can call the WSL or with %%bash for cell magics.
Inside Jupyter Lab I have:
is the %%bash cell magic referring to the WSL? According to my tests yes, I can access the same programs and I am taken to the WSL when I run bash.exe from the Conda prompt. There is an integration of the PowerShell prompt to WSL (https://learn.microsoft.com/en-us/windows/wsl/interop). The same seems to work with the conda prompt.
Here are three options:
If one opens Jupyter notebook via GitBash with jupyter notebook then %%bash magics should work
If one wishes to always be able to run bash within a Jupyter Notebook opened via Anaconda Prompt (similarly using jupyter notebook):
Edit the Jupyter Notebook config file:
Location can be found via Anaconda Prompt with jupyter --config-dir
Open the jupyter_notebook_config.py file in this directory using notepad or an IDE
Modify and save with the line of code: c.NotebookApp.terminado_settings = {} pointed instead to your bash executible (e.g.): c.NotebookApp.terminado_settings = { 'shell_command': ['C:\Program Files\Git\bin\bash.exe'] }
Edit your system environment variables:
Windows Search (with admin rights) > "Edit the System Environment Variables" > Environment Variables > Highlight "path" > Edit > Add a new line with C:\Program Files\Git\bin > OK out of all windows
Set an environment variable in Jupyter Notebook

Resources