launch jupyter notebook in specified browser on cmd line - browser

I'm working on a computer that belongs to my company. I don't have admin privileges, in case that's relevant.
My default browser in Windows 10 is set to InternetExplorer. This is mandated by my company. (Edge or Chrome not allowed as default browser) Although I do have Edge and Firefox installed.
I know that I can change the default browser for jupyter notebook sessions by editing the Jupyter config file. But I don't want to change the default in Jupyter.
Instead, I would like to invoke "jupyter notebook" on the command line (Anaconda prompt) while specifying which browser I want it to pick up.
something like:
jupyter notebook --useBrowser edge
or similar. Is this possible?

Try this:
jupyter notebook --browser="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe %s --new-window"
It is supposed to work like this too: jupyter notebook --browser="firefox" but doesn't in practice for me, because the python webbrowser library (which is used here) is only aware of the default browser. This needs to be manually registered.
You can check this on your system, by running a python prompt and checking:
import webbrowser
list(webbrowser._browsers)
Out: ['windows-default', 'c:\\program files\\internet explorer\\iexplore.exe']

Noticed that if I open Firefox, use the cli command from Kai Aeberli above, as...
jupyter notebook --browser="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe %s --new-window"
and copy and paste one of the URLs from the cli output into the Firefox (non-default browser) address bar, Jupyter Notebook opens in Firefox!
Thanks for this solution! :))

Related

Jupyter notebook open from cmd at any location or any drive

Recently I uninstalled Python and Anaconda. And again reinstalled it. But now I am facing an issue. Previously I was able to open jupyter notebook at any location in any drive by opening Command prompt by typing cmd in the address bar but it's now showing the following error:
> Fatal error in launcher: Unable to create process using '"C:\Python310\python.exe" "C:\Python310\Scripts\jupyter.exe" notebook': The system cannot find the file specified.
How should I handle this now? Please help. I want Jupyter notebook to be open at a specific folder location in a specific drive by opening command prompt through address bar. But not working now.
Your issue is probably related to your Windows environment variables.
To get to the interface, type the following into a terminal window with admin privileges:
rundll32 sysdm.cpl,EditEnvironmentVariables
Under 'Path' make sure that your python installation folder is present, if not add it. For me, python is under 'C:\Anaconda' and jupyter under 'C:\Anaconda\Scripts', but that is for an Anaconda installation. For reference see https://docs.python.org/3/using/windows.html#setting-envvars.
To make sure that everything works, type:
> where python
> where jupyter
You should see the respective installation folders now.

Problem Loading Jupyter Notebook in Windows 10 Pro

I am new in Anaconda (Jupyter Notebbok) and training python. After I installed Anconda when I open Jupyter notebook, the program won't be loaded.
First I run 'jupyter notebook' from the 'command prompt':
Second, when InterneTExplorer loaded and then I click the New>Python3
Finally I expected to have 'jupyter notebook' to write python codes, but I see below picture:
Desired Page:
Can you help me to find the reason for the problem?
In the following link I have attached a video from my Desktop view.
https://www.youtube.com/watch?v=lDvYwHlvghI
Did you try to open the file from the terminal? Create an empty file. In terminal, go to that empty file directory and open that empty file from terminal in Jupyter notebook. Then try to create new .ipynb inside of that file. Just another way to test if it's browser issue or Anaconda download issue.
Command for terminal-
~cd file directory
~jupyter notebook
It will automatically open the Jupyter in your web browser from your terminal.
I copied the 'localhost' link from command prompt in the Firefox browser and solved the problem.

How to change Jupyter lab Working Directory

I'm using the latest version of Jupyter lab on a Windows 10 64 bit machine inside Firefox. When I start the Jupyter lab (via cmd) the default working directory appears to be
c:/windows/system32
(i.e the folder tab on the left) which is a terrible place to be meddling with, at leat for me. I don't know why Jupyter lab starts there. I've installed Jupyter lab using cmd with administrator privileges. Is that why? Should I have it installed just for a user? (My machine has only one user;me).
I tried changing the directory by using
jupyter notebook --generate-config
And inserted a path to my documents folder (in the path for kernels and notebooks line) , edited out the commentary ("#"). And when I restarted Jupyter lab nothing has changed. It shows the
c:/Windows/system32
as default directory which has so many windows folders and is too messy to deal with.
Any solutions will be greatly appreciated. Thanks in advance:)
A late answer to one of the most common Jupyter Notebook or Jupyter Lab questions most new users have about the file/folder structure when they first begin using Jupyter.
For those Windows users who may still be using that old school Windows Command Prompt - which is actually being phased out of Windows, the Windows Command Prompt will normally start-up and display the location where the Windows Command Prompt application is located on the Windows PC:
c:/Windows/system32
In a nutshell, the OP opened the Windows Command prompt, and then the OP typed the following code to start Jupyter Notebook:
Jupyter notebook
But when the OP created / saved the new Notebook file, it was saved to the Windows / system 32 folder - definitely not a location where anyone wants to save their files.
To avoid saving Jupyter Notebook files in the wrong place, the Command Prompt must be started in a different folder or be moved to another directory. One way to move the Command Prompt is by using an old dos command, Change Directory. Just type cd for Change Directory.
Best advice, create a new folder on the C drive and call it Jupyter_Files. Then use old dos, Change Director command, navigate from the location where the command prompt opens and move to that new folder. Do the following to navigate to the new folder.
cd..
cd..
cd Jupyter_Files
Now the Command Prompt is in the location where the Notebook files want to be saved. At the Command Prompt, type: Jupyter notebook. This will create and save those notebook files in this new folder.

How to change Jupyter launch from file to URL?

I installed Python 3.7 from Windows Store, it runs perfectly. I successfully installed Jupyter and other packages with pip from cmd.
The thing is when I run Jupyter (python -m notebook) it says
and automaticaly opens the browser with an ERR_FILE_NOT_FOUND page. Opening the notebook by copy-pasting the URLs works just as expected, so how can I tell Jupyter to run by default the URL instead of the file?
At my end, the file does not open either due to security settings of Chromium (ERR_ACCESS_DENIED).
There's a config parameter which controls how the browser gets access to jupyter: NotebookApp.use_redirect_fileBool (cf. jupyter docs).
In order to change this, create a config by jupyter notebook --generate-config and edit the config file: uncomment and replace the value of line #c.NotebookApp.use_redirect_file = True by c.NotebookApp.use_redirect_file = False. On next start of jupyter, the browser is started using the http URL instead of the file.
HTH
The solution above works (UBUNDU). You just have to bare in mind a few thinks:
1st: If you use jupyter notebook you need to craete this file jupyter notebook --generate-config and look for the line c.NotebookApp.use_redirect_file = True .
If you use jupyter-lab (as I do) you need to use this command jupyter-lab --generate-config . Also, in jupyter-lab you need to find this line c.ServerApp.use_redirect_file = True . In both cases this True needs to become False .
PS. I wanted to add it as a comment but I was not able to do so due to reputation or something.
2nd: It is given in the previous answer but its easy to be missed: you need to uncomment the line (remove the "#" at the start of the line)

Is there a way we can change the working directory of Python (IDLE) permanently?

I am using Python Enthought Canopy. Each time I initiate the editor, I have to change the working directory by typing the code:
import os
os.chdir('C:/Users/Name/Canopy/scripts')
This is quite tedious as the directories are all reset after I quit the editor and start again.
Is there a way that I can change the default working directory, or change the profile of Canopy such that each time the settings will be run before coding?
1) Canopy's GUI is not IDLE.
2) Since this is ipython and has access to ipython magics, you can just type cd ~/Canopy/scripts with no import.
3) But I'm guessing that you have at least one script open in the editor. So you might prefer to just keep the directory synced to the editor, see http://docs.enthought.com/canopy/2.1/quick-start/code_editor.html#change-directory
4) All of the above said, yes you can run arbitrary code on ipython startup. See Ipython Notebook: Default Initialization Python Code

Resources