When I launch ipython notebook, I want it to launch firefox but using a particular firefox profile, which is not my default firefox profile.
In my ipython profile, I have
c.NotebookApp.browser = u'/usr/bin/firefox'
and that makes sure that ipython notebook chooses firefox. However, it chooses the default firefox profile, or else the most recently used firefox profile.
From my linux terminal, I can launch my preferred ipython specific firefox profile (named ipython) like this
firefox -P --no-remote ipython
However, doing
c.NotebookApp.browser = u'/usr/bin/firefox -P --no-remote ipython'
does not work at all (ipython doesn't open firefox at all, and skips to the another browswer'), nor does starting ipython notebook like so
ipython notebook --browser 'firefox -P --no-remote ipython'
which leads to and OSError exception.
Does anyone know of a way to launch firefox with the preferred profile?
A little ugly but maybe better than nothing. I put the following into a shell script to launch firefox and ipython separately but at the same time i.e.
firefox -P ipython -no-remote
ipython notebook --no-browser
You will need to refresh the browser.
My solution uses a script to start firefox with the requested profile and makes Jupyter call it.
Create a script in e.g. /usr/local/bin/firefox-notebook with the following content:
!/bin/env sh
firefox -P notebook $#
Instruct Jupyter to use that script as a browser by adding the following in your jupyter_notebook_config.py:
import webbrowser
browser = webbrowser.Mozilla('firefox-notebook')
webbrowser.register('firefox-notebook', None, browser)
c.NotebookApp.browser = 'firefox-notebook'
You can simply add c.NotebookApp.browser = 'firefox -P notebook --new-window %s' to ~/.jupyter/jupyter_notebook_config.py. (You missed the %s. It will be replaced by the URL at which jupyter is served.)
Related
I have opened my .ipynb file with vscode (Python 3.9 Interpreter - installed jupyterlab), it's connected locally, how can I open it through the browser? what is the default port?
Type:
jupyter notebook in vscode terminal (Ctrl + Shift + ~) and it will start Jupyter in browser of your preference.
If jupyter not installed type:
pip install jupyter in elevated powershell or however you prefer to do installs.
If pip not installed:
python -m pip install -U pip
if python not installed I prefer to install with chocolatey and walkthrough is on their site. https://docs.python-guide.org/starting/install3/win/#install3-windows
I do not have a solution, but only hints. You can let Code start a local server via Ctrl + Shift + P, then Jupyter connect , then select default.
Unfortunately, it's not documented how you can access the server. I gave that feedback on the documentation page.
Source of the image: https://code.visualstudio.com/docs/python/jupyter-support#_connect-to-a-remote-jupyter-server
You can list all running notebooks and their tokens by typing jupyter notebook list in the terminal.
It will output something like this:
Currently running servers:
http://localhost:8889/?token=your_token :: /directory
You can click on the link to open it in the browser.
A solution for CORS-related issues:
In my case, the problem was in my CORS configuration. What fixed it for me was launching the notebook from the terminal with the allowed origin specified:
jupyter notebook --no-browser --NotebookApp.allow_origin_pat=https://.*vscode-cdn\.net
If, for some reason, that doesn't work, you could try the following as a last resort (bearing in mind this will allow ANY origin):
jupyter notebook --no-browser --NotebookApp.allow_origin='*'
Source:
https://github.com/microsoft/vscode-jupyter/wiki/Connecting-to-a-remote-Jupyter-server-from-vscode.dev
On executing the command jupyter notebook, notebook opens on Mozilla Firefox.
How to open notebook on incognito mode of Mozilla Firefox from command line?
In your config add the following to set the default browser to a private firefox (adapted from here and parameters from there):
jupyter_notebook_config.py
[...]
## Specify what command to use to invoke a web browser when opening the notebook.
# If not specified, the default browser will be determined by the `webbrowser`
# standard library module, which allows setting of the BROWSER environment
# variable to override it.
import webbrowser
webbrowser.register('private_firefox', None, webbrowser.get('"' + 'path/to/firefox' +'" -private %s'))
c.NotebookApp.browser = 'private_firefox'
[...]
where path/to/firefox would be something like one of these
/usr/bin/firefox for Linux (see here)
/Applications/Firefox.app/Contents/MacOS/firefox for macOS (see this)
C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe for Windows (as described here)
note:
Other browsers like Chrome ("...\\chrome.exe" --incognitoas in the source) would work analogously, I suppose. I have not tested others. Feel free to comment, if there are any hurdles.
Typically Jupyer opens on http://localhost:8888 all you need to do is copy that url and open it yourself in an incognito Firefox session.
On Safari, if the focus is on an incognito window, the notebook will open automatically in it.
Is there a way to open an IPython interactive console in pycharm that is connected to an existing running kernel (similar to "python --existing")?
btw: in case it's relevant, in my case, the running kernel is of a Jupiter notebook...
EDIT: To clarify, my question is NOT about how to open an interactive console in PyCharm. It is about how to connect that interactive console to a an existing running (Jupiter notebook) Kernel.
(tl;dr: Use jupyter console --existing in the PyCharm "Terminal" tool window (not the "Python Console" tool window) to connect to an existing iPython kernel running in a local Jupyter Notebook server.)
I can confirm that the comment by #john-moutafis suggesting ipython console --existing is the right idea. The command gives "WARNING | You likely want to use jupyter console in the future" so I tried that.
I have a project using a conda environment as its interpreter. Jupyter Notebook is installed in the conda environment.
I open the Terminal tool window. It automatically activates the conda environment.
I type jupyter notebook. The notebook server starts and a browser window opens.
I create a notebook in the browser, and execute a cell containing foo = "bar".
In PyCharm, I open another Terminal tool window by clicking the plus sign to the left of the terminal pane.
In the new terminal I type jupyter console --existing, and it starts an ipython console session.
At the prompt I type dir(), and foo is among the results, confirming that I'm attached to the same kernel as the notebook.
I don't know how it picks which kernel to connect to when there are multiple kernels running in the notebook server.
Don't type exit in the iPython session if you plan to continue using the notebook, it shuts down the kernel.
Unfortunately, tools like Debug and "Execute Line/Selection in Console", which are available for the "Python Console" tool window, are not available for the "Terminal" tool window. In fact, because the Terminal tool window is a simple tool, and that's where I've run my commands, this solution isn't very integrated with PyCharm. The terminal opens in the project directory and activates the conda environment, and it's conveniently adjacent to the editors and tools of the IDE, but otherwise there's no connection to PyCharm's tools.
If anyone can successfully attach PyCharm's integrated PyDev debugger to a running kernel, please chime in.
I'm using PyCharm 2016.3 on macOS 10.12.3.
The easiest way for me is just to type %qtconsole in a jupyter notebook cell and run it. A qt console will open already connected to the running kennel. No PyCharm involved.
I have just installed IPython 2.0 (April 2014) through Anaconda (64 bit) on a brand new pc with windows 7 (64 bit), performed the updates suggested and installed some packages with "$ conda install ".
I am loading IPython notebook with firefox and chrome. they are not the default browsers, so I used the information in this answer: https://stackoverflow.com/a/15748692/2344958
When I run IPython Notebook, it presents the landing pages and open new or imported notebooks, but it does not produce any output for cells.
I have no clue.
The only thing I can see is that the web console reports "Empty string passed to getElementById()."
Console works fine.
Any suggestion?
I found a page describing exactly the problem I had.
here the page:
Getting output with IPython Notebook
I actually have Sophos, but I have no control over it, and the solution that works so far was to start IPython with:
ipython notebook --ip=localhost
It also works by editing the line in configuration file
c.NotebookApp.ip = 'localhost'
I've attempted to read the IPython 0.13 docs, but I've been unable to figure out how to get IPython to default to interactive mode.
Back in IPython 0.10, I could type:
ipython <some_script.py>
and the script would run and drop me to the interactive prompt.
Today, with 0.13, I must add the -i command-line option:
ipython -i <some_script.py>
Can someone please share the ipython config file option that would make IPython 0.13 go directly to interactive mode after running a script?
create default IPython config files first, if you haven't already
ipython profile create
add this line to profile_default/ipython_config.py (you can find profile_default with ipython locate profile)
c.TerminalIPythonApp.force_interact = True
Which is the value that -i sets at the command-line.
With this config, it will be as if you always type ipython -i.