Change Default kernel in jupyter notebook - jupyter-notebook

I am using ipython 6.4.0 on ubuntu 20.04 and using jupyter kernelspec list , I found, there are 2 kernels :
practice_applied_ai
python3
When I open any .ipynb file, it directly opens in "python3" but I want to open it in "practice_applied_ai" because I created virtual environment practice_applied_ai and only in this kernel I can import Tensorflow 2.2.0 for my work.
My question is, Is there any way to change my default kernel without removing any kernel ?

jupyter notebook --generate-config
open the generated config file change
change this line to your desired kernel
#c.MultiKernelManager.default_kernel_name = 'python3'
like
c.MultiKernelManager.default_kernel_name = 'py38'

See this answer on GitHub.
As explained there:
the default kernel name is rarely used. It really only comes into play when a request is received to start a kernel and the kernel name is not specified in the request payload. Since both Notebook and Lab UIs essentially require the user to select a kernel (for new notebooks), it doesn't really come into play.
Put c.MappingKernelManager.default_kernel_name='newDefault' in config file.
To confirm the default is in place, hit the kernelspecs REST API of your running notebook server (e.g., http://localhost:8888/api/kernelspecs) and you should see the default kernel name as the first entry in the returned payload.

Yes this is possible via the .ipynb file itself.
Set the following variables in the metadata, specifically the name which identifies the kernel
"metadata": {
"kernelspec": {
"display_name": "Python 3 (PyTorch 1.6 Python 3.6 CPU Optimized)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/pytorch-1.6-cpu-py36-ubuntu16.04-v1"
},
"language_info": {
"codemirror_mode": {

Not sure how to change the default kernel, but you can change the kernel being used in a notebook, after opening the notebook, as explained in this site.
Open the notebook. Then navigate to Kernel -> Change Kernel and select the kernel you want to use.

Related

Run gym-gazebo on Google Colaboratory

I am trying to run gym-gazebo on Google Colaboratory.
There is a problem to run gazebo server (gazebo without gui) on Colab.
There was warning on display: Unable to create X window. Rendering will be disabled but I think I fix it.
There also warning about sound card. not sure it related Unable to open audio device,
And there warning about conversion Conversion of sensor type[depth] not supported
Here is an example
Can you help?
In order to run gazebo in a headless mode you need to run gserver executable, instead of gazebo. Not sure which one is used by the gym-gazebo toolkit.
In order to still do rendering in gazebo server (e.g. camera view) you would need to use Xvfb (X Virtual Frame Buffer). It is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.
For your specific colab notebook I have changed last cell by adding
get_ipython().system_raw('Xvfb :1 -screen 0 1600x1200x16 &')
in order to create virtual display and added DISPLAY=:1.0 to the beginning of the last line, so it looked as follows
DISPLAY=:1.0 python gym-gazebo/examples/turtlebot/circuit2c_turtlebot_camera_dqn.py
DISPLAY=:1.0 tells X Window client used by gazebo to use virtual display we have created instead of default one :0.
A complete installation of Gazebo on colab and running it in headless server mode with rendering capability can be achieved the following way:
!curl -sSL http://get.gazebosim.org | sh # Install gazebo
!apt-get install -y xvfb # Install X Virtual Frame Buffer
get_ipython().system_raw('Xvfb :1 -screen 0 1600x1200x16 &') # create virtual display with size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
!source /usr/share/gazebo-9/setup.sh && DISPLAY=:1.0 gzserver --verbose # Run gazebo and tell X client to use our virtual DISPLAY :1.0
There is also a way to run full gazebo in simulator with gzweb as a head and link to it using ngrok.io explained here as a fully working notebook. https://colab.research.google.com/drive/1A-miW8cTRKzs7B0m1m4enfiFySzBhsgN
You would need to authenticate to ngrok using your auth token which can be created at ngrok.com in order to connect, because it is lunch as background and doesn't print to cell
!./ngrok authtoken <token>

GoLang debugger chokes on stdin

I have a problem using GoLand's debugger for a piece of code that tries to read from the stdin. For example, the following code:
package main
import (
"io"
"os"
"strings"
)
func main() {
io.Copy(os.Stdout, strings.NewReader("Start typing now...\n"))
io.Copy(os.Stdout, os.Stdin)
}
executes perfectly when I run it from within GoLand - the console window collects the input properly. But when I use the debug command - I can see the my input appearing in the console window, but the enter key will not end the input string, instead the cursor just moves to the next line.
My versions:
GoLand 2018.2.2
Build #GO-182.4129.57, built on August 23, 2018
JRE: 1.8.0_152-release-1248-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
As you are using OSX there is no simple way to get this working.
Assuming you are using Go 1.10 or newer, change the directory to $GOPATH/src/github.com/user/package, then compile your application using go build -gcflags "all=-N -l" github.com/user/package, and then manually start the application in Terminal manually. Once the application runs, go to Run | Attach to Process... and select the application from the list. This will attach the debugger to the running application.
Please note that the compilation step is needed in order to improve the debugging experience but you should not use the resulting binary in production as (almost) all optimizations have been turned off.

How to use Jupyter + SparkR and custom R install

I am using a Dockerized image and Jupyter notebook along with SparkR kernel. When I create a SparkR notebook, it uses an install of Microsoft R (3.3.2) instead of vanilla CRAN R install (3.2.3).
The Docker image I'm using installs some custom R libraries and Python pacakages but I don't explicitly install Microsoft R. Regardless of whether or not I can remove Microsoft R or have it side-by-side, how I can get my SparkR kernel to use a custom installation of R?
Thanks in advance
Docker-related issues aside, the settings for Jupyter kernels are configured in files named kernel.json, residing in specific directories (one per kernel) which can be seen using the command jupyter kernelspec list; for example, here is the case in my (Linux) machine:
$ jupyter kernelspec list
Available kernels:
python2 /usr/lib/python2.7/site-packages/ipykernel/resources
caffe /usr/local/share/jupyter/kernels/caffe
ir /usr/local/share/jupyter/kernels/ir
pyspark /usr/local/share/jupyter/kernels/pyspark
pyspark2 /usr/local/share/jupyter/kernels/pyspark2
tensorflow /usr/local/share/jupyter/kernels/tensorflow
Again, as an example, here are the contents of the kernel.json for my R kernel (ir)
{
"argv": ["/usr/lib64/R/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name": "R 3.3.2",
"language": "R"
}
And here is the respective file for my pyspark2 kernel:
{
"display_name": "PySpark (Spark 2.0)",
"language": "python",
"argv": [
"/opt/intel/intelpython27/bin/python2",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"env": {
"SPARK_HOME": "/home/ctsats/spark-2.0.0-bin-hadoop2.6",
"PYTHONPATH": "/home/ctsats/spark-2.0.0-bin-hadoop2.6/python:/home/ctsats/spark-2.0.0-bin-hadoop2.6/python/lib/py4j-0.10.1-src.zip",
"PYTHONSTARTUP": "/home/ctsats/spark-2.0.0-bin-hadoop2.6/python/pyspark/shell.py",
"PYSPARK_PYTHON": "/opt/intel/intelpython27/bin/python2"
}
}
As you can see, in both cases the first element of argv is the executable for the respective language - in my case, GNU R for my ir kernel and Intel Python 2.7 for my pyspark2 kernel. Changing this, so that it points to your GNU R executable, should resolve your issue.
To use a custom R environment I believe you need to set the following application properties when you start Spark:
"spark.r.command": "/custom/path/bin/R",
"spark.r.driver.command": "/custom/path/bin/Rscript",
"spark.r.shell.command" : "/custom/path/bin/R"
This is more completely documented here: https://spark.apache.org/docs/latest/configuration.html#sparkr

Jupyter Creating Notebook failed: FORBIDDEN

I have just upgraded Jupyter to the version 4.3.1
While I can open previously created ipynb files, I cannot create new ones.
When I try to create a new notebook file, I get a pop up windows saying:
Creating Notebook Failed
An error occurred while creating a new notebook
Forbidden
In the terminal I notice this output:
[W 12:53:23.375 NotebookApp] 403 POST /api/contents (::1): '_xsrf' argument missing from POST
[W 12:53:23.383 NotebookApp] 403 POST /api/contents (::1) 8.92ms referer=http://localhost:8888/tree?token=e7fbbb58516dc1359fcc26a1079093166a1f713ee5b94ccd
I use Jupyter with Python 3.5.2 and IPython 5.1.0
Another alternative to confirm the issue is to open your Jupyter Session in another browser and you might be redirected to a screen like the following:
If you open a new console and type
jupyter notebook list
You'll see your current notebook and the URL will contain a token. Open that in a new tab and problem solved.
Output command should look like this:
Currently running servers:
http://localhost:8888/?token=cbad1a6ce77ae284725a5e43a7db48f2e9bf3b6458e577bb :: <path to notebook>
I had to enable cookies in the browser (which I had intentionally disabled). Then the "Forbidden" error disappeared, everything is OK now.
The generally accepted solution to prevent XSRF is to cookie every user with an unpredictable value and include that value as an additional argument with every form submission on your site.
From: http://tornado.readthedocs.io/en/latest/guide/security.html#cross-site-request-forgery-protection
Jupyter blocks non-local requests. To access Jupyter from an external address we can execute it with the following parameters:
jupyter notebook --NotebookApp.allow_origin=* --NotebookApp.allow_remote_access=1
I had this problem just now, but I noticed that it worked in Edge. Deleting all browser cache including cookies in Chrome solved this in my case.

Installing terminator on cygwin

After going through a lot of sites about best terminal for system admins I was trying to install on Cygwin. Unfortunately, I did not find any good site with instruction about how to do it.
Is anyone done this before? Please help me with steps and packages that I need to install.
Also is there any terminals I can try (like Cygwin)?
I don't know since what version, but now you can install terminator just from the Cygwin installer. And runs great
Regards
If you don't want to use cygwinports, you can actually install all of terminator's dependencies from the cygwin installer, except for terminator itself.
In the cygwin installer select and install:
python-dbus
python-gobject
python-gtk2.0
python-vte (under GNOME tab for some reason)
GConf2
Then, pull down the latest terminator tarball from https://launchpad.net/terminator/+download and extract it somewhere. In a administrator terminal just run python setup.py install and as long as you have a running X server just running terminator will work perfectly.
The sources about how to install terminator are a bit obscures. What I did, and may help you, was this: (although I'm still having segmentation faults errors)
Update your Cygwin to the latest
Open a Cygwin terminal and run: (if you have the x86 version use that. The idea of this step is to use Cygwin Ports)
cygstart -- /your/cygwin/path/setup-x86_64.exe -K http://cygwinports.org/ports.gpg
In the section Choose A Download Site:
Add "http://downloads.sourceforge.net/cygwin-ports"
Add " ftp://ftp.cygwinports.org/pub/cygwinports"
Select another mirror close to you
Check that you have a total of three URLs selected
It may show you warning about not loading the .ini configuration but ignore them (Note: I looked for different port URLs but the official ones threw me errors and I could not pass this step, that's why I used alternatives URLs)
First, you need to install the packages for the X Window:
http://x.cygwin.com/docs/ug/setup.html
Basically they are:
xorg-server (required, the Cygwin/X X Server)
xinit (required, scripts for starting the X server: xinit, startx, startwin (and a shortcut on the Start Menu to run it), startxdmcp.bat )
xorg-docs (optional, man pages)
Also search and select the terminator package
It takes quite a while before it finishes.
Go to Start->All Programs->Cygwin-X->X Win Server (windows tool bar)
A xterm window should open. Type:
terminator
You should know have terminator with Cygwin.
Note: After I run terminator I get this error:
/usr/lib/python2.7/site-packages/terminatorlib/terminator.py:87: Warning: Attempt to add property GnomeProgram::sm-connect after class was initialised
self.gnome_program = gnome.init(APP_NAME, APP_VERSION)
/usr/lib/python2.7/site-packages/terminatorlib/terminator.py:87: Warning: Attempt to add property GnomeProgram::show-crash-dialog after class was initialised
self.gnome_program = gnome.init(APP_NAME, APP_VERSION)
/usr/lib/python2.7/site-packages/terminatorlib/terminator.py:87: Warning: Attempt to add property GnomeProgram::display after class was initialised
self.gnome_program = gnome.init(APP_NAME, APP_VERSION)
/usr/lib/python2.7/site-packages/terminatorlib/terminator.py:87: Warning: Attempt to add property GnomeProgram::default-icon after class was initialised
self.gnome_program = gnome.init(APP_NAME, APP_VERSION)
Warning: python-keybinder is not installed. This means the hide_window shortcut will be unavailable
Unable to bind hide_window key, another instance/window has it.
Segmentation fault (core dumped)
I've looking to fix this issue but sadly I couldn't find anything. If you use Cygwin x86 your outcome can be different.
Hope this can help you.

Resources