I'm on a windows machine without admin right and I would like to run jupyter on chrome, while the default browser is another.
I have a local installation of the Anaconda distribution and my first option to start jupyter would be through the Anaconda Navigator, but maybe I have to do something else. Because it is a local installation the command line jupyter notebook produces no results.
When I paste the url address in the default browser I have (something like http://localhost:8892/notebooks/Home/Exercices/Testing1.ipynb the chrome page asks me for a password or token. I have no password and I do not know what a token is.
Is there a way to change the browser of the Anaconda Navigator? or how can I start jupyter with Chrome?
Thanks to #Darthbith and this post How to change the default browser used by the ipython/jupyter notebook in Linux? I was able to figure it out:
Step 1: To open Anaconda Prompt from the Start Menu and type
# for old notebook and JupyterLab < 3.0, or
jupyter notebook --generate-config
# for new nbclassic and JupyterLab >= 3.0
jupyter server --generate-config
This will generate the file ~/.jupyter/jupyter_notebook_config.py (or jupyter_server_config.py for nbclassic/new JupyterLab)
Step 2: Edit this file and change the following line (chrome is also is also in a local installation)
# for old notebook and JupyterLab < 3.0
c.NotebookApp.browser = u'C:/Home/AppData/Local/Google/Chrome/Application/chrome.exe %s'
# OR for new nbclassic and JupyterLab >= 3.0
c.ServerApp.browser = u'C:/Home/AppData/Local/Google/Chrome/Application/chrome.exe %s'
In Windows, write in cmd/ Anaconda Prompt:
jupyter notebook --generate-config
The jupyter_notebook_config.py file generated is situated in "C:\Users\YourName\.jupyter\" folder.
Open it using a text editor and change #c.NotebookApp.browser = '' to
import webbrowser
webbrowser.register('chrome', None, webbrowser.GenericBrowser(u'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'))
c.NotebookApp.browser = 'chrome'
and save the file.
Now execute the jupyter-notebook command and the set browser will be used.
I don't know the precise details for Windows, but this is how to set the default browser on a Mac:
jupyter notebook --generate-config
This creates a file jupyter_notebook_config.py in ~/.jupyter. Edit the line
#c.NotebookApp.browser = ''
On a Mac I set it to:
c.NotebookApp.browser = u'open -a /Applications/Gooogle\ Chrome.app %s'
You just need to figure out how to point it to Chrome on Windows.
As far as I know, there's no way to change the default browser that opens. However, you can find the token for the Notebook server by opening Anaconda Prompt from the Start Menu and typing
jupyter notebook list
This will give you a URL with the token that you can copy/paste into any other browser. The output of the list command looks like
Currently running servers:
http://localhost:8888/?token=41429d3dcf554d0dde69498aac0950654a590664ba02b3cd :: /path/to/home/folder
So you can either type http://localhost:8888 into the browser and then copy/paste the token into the field, or just copy/paste the whole URL with the token.
The following also works for me. I give it a full path to chrome, plus %s at the end.
jupyter notebook --browser='C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
If chrome is in the PATH environment variable, the following might work too.
jupyter notebook --browser=chrome
You don't need to change anything in the jupyter_notebook_config file. check whether your default web browser(if it's chrome) or reset and again choose as a web browser(chrome for me)as a default browser. it worked for me.
I'd like to offer a little more information about what to put in your jupyter_notebook_config.py file than is included in any of the other answers. jupyter is using python's webrowser module to launch the browser by passing the value for c.NotebookApp.browser to the webbrowser.get(using=None) function. If no value is specified, the function selects the user's default browser. If you do specify a value here, it can be interpreted in one of two ways, depending on whether or not the value you specified ends with the characters %s.
If the string does not contain the characters %s
it is interpreted as a browser name and the module checks if it has a browser registered with that name (see the python documentation for which browsers are registered by default). This is why Abhirup Das's answer works, first the webbrowser module is imported
import webbrowser
the chrome browser is registered with the module
webbrowser.register('chrome', None, webbrowser.GenericBrowser(u'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'))
and finally, the jupyter server is fed the browser name
c.NotebookApp.browser = 'chrome'
This browser registration does not persist, so the process must be repeated every time the server is launched.
Alternatively, if the string does contain the characters %s, it is interpreted as a literal browser command. Since this question is about how to run the browser on Windows, the browser command will probably contain backslashes. The backslash is used in python string literals to escape any characters that otherwise have any special meaning (e.g., to include a quote or double quote inside the string literal). Any backslashes in the browser command need to be be escaped or replaced. The easiest way is to replace the backslashes in the command with foward slashes, e.g.,
'C:/Home/AppData/Local/Google/Chrome/Application/chrome.exe %s'
rather than
'C:\Home\AppData\Local\Google\Chrome\Application\chrome.exe %s'
I for the life of me couldn't get unicode/raw string commands or commands where I escaped each backslash with an extra backslash to work, so replacing the backslashes with forward slashes may be the only option. I verified that the strings I tried all worked in python, so the only way to be sure would be to look at the jupyter source code.
Anyway, since registering a browser with the module does not persist, if your browser isn't already registered by default, it is probably best to use a literal browser command with the backslashes replaced with forward slashes.
On Mac this works:
1) Generate a config file from within your environment:
jupyter notebook --generate-config
This will place jupyter_notebook_config.py in ~/.jupyter.
2) Modify the following line in jupyter_notebook_config.py:
c.NotebookApp.browser = 'open -a /Applications/Google\ Chrome.app %s'
For linux users:
First generate config file using:
jupyter notebook --generate-config
Then open the generated file and look for #c.NotebookApp.browser = ''
Edit it to : c.NotebookApp.browser = '/bin/brave %s'
Replace /bin/brave with whatever your browser executable location is.
The explanations above didn't work for me, I guess, I mistyped something. Actually it was easier for me to change default browser to Chrome and then Jupiter automatically starts in Chrome after next launch. (Search Windows - change default browser).
Jupyter looks for the BROWSER environment variable when choosing which browser to launch.
I recommend setting BROWSER over configuring Jupyter specifically, because setting BROWSER is the default way to specify which browser you prefer, regardless of which application it applies to.
To choose the browser for a single session, set the BROWSER environment variable when running the jupyter process.
BROWSER=chromium-browser jupyter notebook when you have chromium-browser when you prefer to use chromium-browser on PATH. Typical for Linux.
BROWSER=C:/Home/AppData/Local/Google/Chrome/Application/chrome.exe jupyter notebook when you don't have the application on PATH. Typical for Windows.
BROWSER=<your browser> jupyter notebook otherwise.
To choose browser for your whole system, set the BROWSER environment variable globally.
Find .../jupyter/runtime/nbserver-11596-open.html file, or whatever the file name is, you can find the file name when jupyter notebook starts, and associate it with Chorme worked for me.
Open anaconda prompt and type
jupyter notebook --generate-config
then go to "jupyter_notebook_config.py" path and add following line
c.NotebookApp.browser = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
Is there any way to run jupyter on chrome in /tmp ?
something like that:
jupyter notebook --browser='google-chrome --user-data-dir=/tmp/'
There is a much simpler way than typing commands in the command window, you can use the Windows file explorer!
Simply navigate to the following path C:\Users\**YourUser**\AppData\Roaming\jupyter\runtime\, as below:
There, among other files, you will see the corresponding .html files of your jupyter jobs. You can right-click on any .html file, select "Open As" as then select other application (as shown on the image below - apologies my default language is in Spanish).
From here, you can select the most suitable navigator for you. In my case I am using Firefox, but you can choose Chrome or whatever (as shown below). Make sure to click the "Use always this application to open .html files" checkbox to set Chrome as the default navigator.
From now on, Jupyter Notebooks will always open in Chrome. Hope it helped!
Make sure to activate the line by removing the # comment indicator.
After considerable thrashing about trying to launch a jupyter notebook in chrome from Anaconda in Win10 when chrome was not my default browser, I combined several of the suggestions above and, in the jupyter_notebook_config.py file under .jupyter in my home directory put in these lines in place of the default c.NotebookApp.browser line, and it finally worked!:
import webbrowser
webbrowser.register('chrome', None, webbrowser.GenericBrowser(u'C:/PROGRA~2/Google/Chrome/Application/chrome.exe'))
c.NotebookApp.browser = 'chrome'
Note the use of Unix-style directory separators (this is apparently a bug in webbrowser) and the use of DOS-style "PROGRA~2" --- both of these seem to be necessary. Adding "%s" after "chrome.exe" seemed not to help.
To achieve this on Windows 10, I had to do the following:
For a temporarily choose/specify a browser from the Anaconda Prompt CLI (note the order/type of quotes, they seem to be different to most other answers as those answers failed to work for me):
jupyter notebook --browser="'C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe' %s"
To set it permanently, edit the jupyter_notebook_config.py file in your .jupyter folder. I'm not certain that you need to escape the backslashes (i.e. \ vs just ), but I used the following and it worked (again, note that the order/type of quotes is different):
c.NotebookApp.browser = '"C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe" %s'
In my case, macOS 10.15.4 with anaconda 1.9.12, finally, I found an effective one as below:
c.NotebookApp.browser = u'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome %s'
I hope this helps someone. :-)
Jupyterlab 3 migrated from notebook server to plain jupyter server. To select the browser jupyter lab will open, put the config in .jupyter/jupyter_server_config.py and replace NotebookApp by ServerApp. For example:
c.ServerApp.browser = '/usr/bin/firefox -P notebook --new-window %s'
if you didn't specify a browser for your jupyter notebook, maybe just changing the default browser of your operating system can solve your issue; like it did for me.
check default browser in window:
default apps: web browser
Check your default browser's configurations, The default browser is where the Jupyter Notebook will open in.
on Windows, Simply change it doing:
Search in the start menu "Default apps", open it.
Under Web browser, select the browser currently listed, and then simply change it to your desired browser (where you want the Jupyter Notebook to open).
here are the steps
Open Anaconda promt and write:
jupyter notebook --generate-config
go to that path and open with a text editor the .py file
In that file look for the line that constains the follow text:
#c.NotebookApp.browser = ''
Befor that line write the follow code
import webbrowser
webbrowser.register('chrome', None, webbrowser.GenericBrowser(u'C:/PROGRA~2/Google/Chrome/Application/chrome.exe'))
drop de symbol # in the lines to set the browser, so it looks like:
c.NotebookApp.browser = ''
save the file, this makes Chrome as a default browser to launch jupyter notebook
use this command(windows cmd):
jupyter notebook --browser NotebookApp.browser
it generates a link (localhost link), copy paste it in any browser that you need and use you notebook.
Microsoft have setup Edge as a persistent virus on Windows. Even if you set the default browser to Chrome in Settings, you still get edge when opening up Jupyter.. This is because Microsoft have set Edge as the default app for .htm and .html files. In the settings for app defaults, find that one and change it to Chrome and you are all set..
Easy steps:
1. Uninstall the current browser which notebook picks on launch.
2. Launch the notebook again, it will ask for browser: choose the required one and enable the clause which says : (something like) Always choose this application for this types of files.
It will work.
Install back you uninstalled browser.
Related
I am running Jupyter Notebook on a windows x64 machine. My documents folder is synchronized on a corporate network (green circle icon thing) and it looks like the path is \(network path stuff)...\myname\My Documents. I tried setting this (with backslashes replaced by forward slashes) as the value of c.NotebookApp.notebook_dir in my jupyter_notebook_config.py, but when I do that jupyter-notebook tells me "No such notebook dir:" and closes.
Is there any way to get Jupyter Notebook to use this synchronized path as the notebook directory? Apologize for the lack of clarity on what sort of synchronization applies to my windows folder.
Thanks to LinkBerest for helping me arrive at the following answer:
Replace ALL backslashes with slashes including the leading double backslashes (if any).
If specifying the default directory in the config file does not work, can remove the corresponding item from the config file and just navigate to the synced folder in got-bash before starting jupyter-notebook.
Whether specifying in the config file or navigating to the directory before starting, if I use the "replace all backslashes with slashes" then it works.
I set (appended) the path to new install of sqlite3. it didn't work in my vscode terminal afterward, only working in cmd. So, I set it again in vscode as well, assuming that vscode is running a different terminal, requiring its own path variable,,, but when I came back later that day after shutdown and new startup, the path for sqlite3 needed to be added again. it appears as though I will need to add it every time I want to use sqlite3 in my vscode terminal
I'm pretty newb, so I haven't tried much other than setting it again, then trying to look up the keywords on google and the vscode documentation, but so far I haven't found a setting or command to save the path variable permanently.
Press ctrl + comma
Search for terminal integrated shell + your OS
Type in the path of sqlite shell (You can use whereis sqlite3)
You can also add line "terminal.integrated.shell.${yourOS}" : "path/to/shell" to your global settings.json file.
I am trying to open http://localhost in (any) browser from WSL bash terminal.
So far I have tried:
How can I open Google Chrome from the terminal with the URL "localhost:3000"?
"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows
How to mention C:\Program Files in batchfile
No luck in setting up BROWSER variable for xdg-open, it responds to xdg-open http://localhost with /usr/bin/xdg-open: 851: /usr/bin/xdg-open: /c/"Program: not found.
I have tried escaping with \ and ^. Using %ProgramFiles(x86)% and ofcorse "Program Files (x86)". More or less it is the same answer every time... Any ideas how to set a work flow for opening browser in WSL?
So far I've ended up with:
/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe localhost
But I am looking for more elegant solution.
You can invoke the Windows command line from Bash and use Windows file association to open URL with the default Windows browser.
To do so just type in Bash:
cmd.exe /C start http://localhost
In my case this loads localhost in Chrome, note that the full URL is necessary for Windows to decide what to do.
This is similar to what open does in MacOS, hence you may find useful to directly alias the command and use it also for other type of files:
# add this to .bash_aliases
open='cmd.exe /C start'
Now you can open URL or open file.pdf directly from WSL.
Note: since you are simply redirecting commands to cmd.exe, it needs to have access to the file your working with. As a consequence the above solution will work when you find yourself in the Windows file system, but probably will fail when you are working with files in Linux partition (i.e. in the tmp or in the bin folder). This probably has been fixed in the new version of the WSL but I have not tested it.
You are almost there. Just add an alias for the windows chrome executable
http://www.linfo.org/alias.html
alias chrome="/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"
Now you can simply run chrome localhost and open chrome in any web location you desire.
To open localhost in browser from bash terminal, you need to configure wsl so that it defaults to whatever browser has been set as default in your windows 10 system.
You can do this by using some tools from wslu ("A collection of utilities for WSL").
For this purpose you need.
wslview (-u, --unregister "remove wslview as the default WSL web browser.
-r, --register "register wslview as the default WSL web browser.)
wslpath (-a "force result to absolute path format",
-u "translate from a Windows path to a WSL path (default)")
You need to register your preferred browsers like this...
For Google Chrome:
wslview -r $(wslpath -au 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
For Microsoft Edge:
wslview -r $(wslpath -au 'C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe')
Now you can open localhost as x-www-browser localhost:8080 or www-browser localhost:8080 and x-www-browser or www-browser will default to whatever is your current windows 10 default browser provided it has been registered as described above.
Do not forget to indicate the port; localhost alone did not work for me.
To unregister any browser just change the -r flag to -u.
Have a look at wslview help: info wslview <enter> in the wsl terminal
and wslpath <enter> for help with wslpath.
Install wslu (A collection of utilities for WSL) https://github.com/wslutilities/wslu#feature and then add these two lines to your shell's RC file, e.g. .bashrc or .zshrc.
export DISPLAY=:0
export BROWSER=/usr/bin/wslview
You can set the BROWSER variable as you have done . But xdg-open won't work in WSL as the
xdg-openscripts are setup to work with unquoted environment variables ( in which case ,
the path breaks due to spaces in the pathname ).
You can use the wsl-opennpm utility to do the same for WSL .
Once you have npm installed , install wsl-open utility :
sudo npm install -g wsl-open
To open any URL with default Windows Browser :
wsl-open http://google.com
You can also set wsl-open as default program for a file type in WSL :
wsl-open -w // sets wsl-open as the Shell Browser
Then you can use the standard xdg-open for URLs as well with default windows browser :
xdg-open http://google.com
I created a script that basically forwards xdg-open to powershell -c start
Not tested much though.
sudo tee /usr/local/bin/xdg-open <<EOF
#!/bin/sh
powershell.exe -c start "'\$#'"
EOF
sudo chmod +x /usr/local/bin/xdg-open
Cheers
Oliver
Came across this article that worked for me:
https://towardsdatascience.com/running-jupyter-notebook-on-wsl-while-using-firefox-on-windows-5a47ebfae4c1
In short:
Step 1 - Generate config for Jupyter Notebook:
jupyter notebook --generate-config
Step 2 - Edit the config file using "nano" or other editor
The config fileshould be under your home directory under ".jupyter" folder:
~/.jupyter/jupyter_notebook_config.py
Step 3 - Disable launching browser by redirecting file
First comment out the line, then change True to False:
c.NotebookApp.use_redirect_file = False
Step 4 - add a line to your .bashrc file to set the BROWSER path
export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
For me it was Chrome under my Windows Program File. Otherwise any linux installation under WSL doesn't have a native browser to launch, so need to set it to the Windows executable.
Step 5 - restart .bashrc
source .bashrc
That should work!
https://github.com/microsoft/WSL/issues/3632#issuecomment-690061348
export BROWSER='eval "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"'
xdg-open https://google.com # nice work
solved the spaced path problem.
it worked for me.
Now you can simple use :
sensible-browser http://www.google.com
it already comes with wsl and it opens the default browser in windows
ps: you can also use wslview . to open the file explorer from the bash terminal
i'll give you a suggestion, it could be opened via visual studio code in wsl. And install the live server plugin.
Ok so first of all, I don't use windows anymore so I can't post a full solution that I've personally tested, but back when I did use windows, I use to do this and it worked. (This should probably be a comment, but a while back I deleted some unaccepted answers and lot the associated reputation :/)
Solution:
Don't try to launch your windows programs from inside WSL, instead install the linux version of the program and an X server, such as Xming. Here is an example tutorial for forwarding X apps back to Xming on windows.
Summarized, install Xming (on Windows). Then export the DISPLAY variable:
export DISPLAY=:0
Install google-chrome inside WSL and launch it via the CLI. It should show up on your desktop.
Note: There's also a way to use PuTTY alongside XMing for remote viewing, but you'll need to disable Windows firewalls and install the full openssh-server inside WSL first.
I am using a cygwin shell in windows 10. I am trying to figure out how to open chrome from the command line. I have tried typing chrome, google-chrome, chromium-browser, start chrome, open chrome, and many variations. I have even tried using my python shell, and I have also tried going to the folder where chrome.exe is located and opening it from there. The main reason I want to figure it out is because I plan to write HTML documents with python and then open them in chrome. Any ideas?
Did you try ./chrome.exe while being in the directory where the file is located? The path ./ is probably needed before the file name since the executable is not in a standard system path. You can of course also specify the full path to the file as well.
Use
cygstart "C:\path\to\chrome.exe"
or to open a specific URL,
cygstart "http://my/url.htm"
I've downloaded a couple of ipython notebooks, and I'd like to open them in browser tabs without navigating to the directory I've downloaded them to and running ipython notebook notebook_name.ipynb.
I realize this probably means I'm lazy, but it seems like a common use case to me. Am I missing something obvious?
Use Pineapple application for opening and working on your IPython/Jupyter notebooks. It is pretty cool.
Update:
Now there is nteract, which is a new jupyter-like Desktop app. After installing it, make it the default app for opening .ipynb files. Then just double-click any notebook to start it right away.
I have found a nice way using Automator (Oct. 2017; with information from here):
open Automator and create a new Application
to add Run Shell Script drag and drop it from the list; might need these settings Shell: /bin/bash and Pass input: as arguments
insert the code below; if necessary adjust the path to jupyter
Code
#!/bin/sh
variable="'$1'"
the_script='tell application "terminal" to do script "/usr/local/bin/jupyter notebook '
osascript -e "${the_script}${variable}\""
save the script as an application (!)
try to open a .ipynb file and change the default app to this newly created one.
notes
This will open a terminal and run the jupyter notebook command, such that you can interrupt and stop the notebook-server from there.
Also note that you cannot test the app like that in Automator, but need to add the Get Specified Finder Items and insert some test notebook there (just for testing purposes).
As pointed out in the comments, there are two more notes:
To avoid spamming your browser history with notebooks, you can start your notebooks in incognito/private mode: Run jupyter notebook in incognito window
If you want to run notebooks in one server and don't mind an extra tool, Sachit Nagpal has pointed out (thank you), that one could also use nbopen. To use this workflow just replace "/usr/local/bin/jupyter notebook ' with "nbopen '. Any other tool should work alike.
pip install nbopen.
open Automator, create new Application
Drag'n drop Run Shell Script
Change Pass input to as arguments
Copy/paste this script:
variable="'$1'"
the_script='tell application "terminal" to do script "nbopen '
osascript -e "${the_script}${variable}\""
Save the new application to Applications directory as nb_open
Right click any ipynb file and select "Open with > Other" and select the nb_open in the Applications folder. Don't forget to check "Always Open With".
Select an ipynb file, get info (command + i) > Open With (select nb_open if not selected already) > Click Change All.... Done.
The application posted here worked pretty well for me: http://bioequity.org/2013/11/16/ipynbviewer/
You also need to download iTerm2, as described on that page.
Note that this doesn't work if there are spaces in the filename, but you can modify it so that it works with spaces in the filename. Control-click on the iPyNbViewer.app and select "Show package contents". Edit the file Contents/Resources/Scripts/main.scpt. Change three instances of "POSIX path" to "quoted form of POSIX path". Now it will work with spaces in the filename.
To set all of your .ipynb files to open with the app, you'll need to Get Info (command-I) on one of the files and select the iPyNbViewer app to open all .ipynb files.
It would be great if this was the default behavior of double-clicking on an iPython notebook file...
I came up with a way of doing it on Ubuntu. (It works for me but I can take no responsibility). It's explained here. In a nutshell, you need to create a new MIME type, then write a script that works as the app that launches them:
#!/bin/bash
netstat -tln |grep "8902"
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
ipython notebook / --no-browser --port=8902 &
sleep .5
fi
xdg-open http://localhost:8902/notebooks$1
This always opens the notebook server on port 8902, but first checks whether there is already a server running, and, if so, uses it.
Then you can use ubuntu tweak to select your script as a default application for the MIME type "IPython Notebook" you just created.
Not very elegant, but worth it, in my opinion.
PyCharm now supports Jupyter ipynb files:
which is from the documentation https://www.jetbrains.com/help/pycharm/editing-jupyter-notebook-files.html.
But I think this feature is only available in the Professional version now; hopefully it will be added to the Community version in the future.
Look at this link.
Put a bash script in the folder where you keep your ipython notebooks and simply double click it to open up a notebook instance. From the link above, the bash script has just:
path=$0 # path is path to this file
cd ${path%/*.*} # clip off the file name to get directory path and cd
ipython notebook --pylab inline
Finally, you need to chmod u+x the script to make it executable and you're done.
I have used the command line application 'nbopen' and put it in a Platypus wrapper to get drag'n drop and double click opening on Macos. 'nbopen' is downloadable using 'pip'
It works well when used as described above by DanHickstein.
Only problem with my code is that it requires the full path to the nbopen command. I know I should be able to use 'which nbopen' somehow but can't get it to work.
Heres my Platypus code:
#!/bin/bash
# Opens ipynb files in a Jupyter Notebook
# echo $1
# $1 is the path of the dropped file
/Users/robw/anaconda/bin/nbopen $1
# Based on an idea from
# https://www.quora.com/Is-there-a-straightforward-way-to-open-an-IPython-Notebook-in-Windows-by-double-clicking