{"id":5734,"date":"2015-04-28T15:14:53","date_gmt":"2015-04-28T14:14:53","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=5734"},"modified":"2015-04-28T15:14:53","modified_gmt":"2015-04-28T14:14:53","slug":"a-portable-jupyter-ipython-install-on-windows-with-an-r-kernel","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=5734","title":{"rendered":"A portable Jupyter (IPython) install on Windows with an R kernel"},"content":{"rendered":"<p>I recently found myself in need of a portable install of the <a href=\"http:\/\/sourceforge.net\/projects\/rportable\/files\/\">Jupyter notebook<\/a> which made use of a portable install of R as the compute kernel. When you work in institutions that have locked-down managed Windows desktops, such portable installs can be a life-saver! This is particularly true when you are working with rapidly developing projects such as Jupyter and <a href=\"https:\/\/github.com\/IRkernel\/IRkernel\">IRKernel<\/a>.<\/p>\n<p>It&#8217;s not perfect but it works for the fairly modest requirements I had for it.\u00a0Here are the steps I took to get it working.<\/p>\n<p><strong>Download and install Portable Python<\/strong><\/p>\n<p><strong><\/strong>I downloaded Portable Python 2.7.6.1 from\u00a0<a href=\"http:\/\/portablepython.com\/\">http:\/\/portablepython.com\/<\/a> and installed into a directory called\u00a0<strong>Portable Python 2.7.6.1<\/strong><\/p>\n<p><strong>Update IPython and install the extra modules we need<\/strong><\/p>\n<p>This version of Portable Python comes with a portable IPython instance but it is too old to support alternative kernels. As such, we need to install a newer version.<\/p>\n<p>Open a <strong>cmd.exe<\/strong> command prompt and navigate to <strong>Portable Python 2.7.6.1\\App\\Scripts<\/strong>.<\/p>\n<p>Enter the command<\/p>\n<pre>easy_install ipython.exe<\/pre>\n<p>You&#8217;ll now find that you can launch the ipython.exe terminal from within this directory:<\/p>\n<pre>C:\\Users\\walkingrandomly\\Desktop\\Portable Python 2.7.6.1\\App\\Scripts&gt;ipython\r\nPython 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]\r\nType \"copyright\", \"credits\" or \"license\" for more information.\r\n\r\nIPython 3.1.0 -- An enhanced Interactive Python.\r\n?         -&gt; Introduction and overview of IPython's features.\r\n%quickref -&gt; Quick reference.\r\nhelp      -&gt; Python's own help system.\r\nobject?   -&gt; Details about 'object', use 'object??' for extra details.\r\n\r\nIn [1]: exit()<\/pre>\n<p>If you try to launch the notebook, however, you&#8217;ll get error messages. This is because we haven&#8217;t taken care of all the dependencies. Let&#8217;s do that now. Ensuring you are still in the\u00a0<strong>Portable Python 2.7.6.1\\App\\Scripts\u00a0<\/strong>folder, execute the following commands.<\/p>\n<pre>easy_install pyzmq\r\neasy_install jinja2\r\neasy_install tornado\r\neasy_install jsonschema<\/pre>\n<p>You should now be able to launch the notebook using<\/p>\n<pre>ipython notebook<\/pre>\n<p><strong>Install portable R and IRKernel<\/strong><\/p>\n<ul>\n<li>I downloaded Portable R 3.2 from\u00a0<a href=\"http:\/\/sourceforge.net\/projects\/rportable\/files\/\">http:\/\/sourceforge.net\/projects\/rportable\/files\/<\/a>\u00a0and installed into a directory called\u00a0<strong>R-Portable<\/strong><\/li>\n<li>Move this directory into the Portable Python directory. It needs to go inside\u00a0<strong>Portable Python 2.7.6.1\\App\u00a0<\/strong>(<a href=\"https:\/\/github.com\/jupyter\/jupyter_notebook\/issues\/53\">see this discussion<\/a> to learn how I discovered that this location was the correct one)<\/li>\n<li>Launch the Portable R executable which should be at\u00a0<strong>Portable Python 2.7.6.1\\App\\R-Portable\\R-portable.exe\u00a0<\/strong>and install the <a href=\"https:\/\/github.com\/IRkernel\/IRkernel\">IRKernel<\/a> packages by doing<\/li>\n<\/ul>\n<pre>install.packages(c(\"rzmq\",\"repr\",\"IRkernel\",\"IRdisplay\"), repos=\"http:\/\/irkernel.github.io\/\")<\/pre>\n<p><strong>Install additional R packages<\/strong><\/p>\n<p>The version of Portable R I used didn&#8217;t include various necessary packages. Here&#8217;s how I fixed that.<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\"><span style=\"line-height: 13px;\">Launch the Portable R executable which should be at\u00a0<strong>Portable Python 2.7.6.1\\App\\R-Portable\\R-portable.exe<\/strong>\u00a0and install the following packages<strong>\u00a0<\/strong><\/span><\/span>\n<pre>\r\ninstall.packages('digest')\r\ninstall.packages('uuid')\r\ninstall.packages('base64enc')\r\ninstall.packages('evaluate')\r\ninstall.packages('jsonlite')<\/pre>\n<\/li>\n<\/ul>\n<p><strong>Install the R kernel file<\/strong><br \/>\nCreate the directory structure <strong>Portable Python 2.7.6.1\\App\\share\\jupyter\\kernels\\R_kernel<\/strong><\/p>\n<p>Create a file called <strong>kernel.json<\/strong> that contains the following<\/p>\n<pre>{\"argv\": [\"R-Portable\/App\/R-Portable\/bin\/i386\/R.exe\",\"-e\",\"IRkernel::main()\",\r\n\"--args\",\"{connection_file}\"],\r\n \"display_name\":\"Portable R\"\r\n}<\/pre>\n<p>This file needs to go in the <strong>R_kernel<\/strong> directory created earlier. Note that the kernel location specified in kernel.json uses Linux style forward slashes in the path rather than the backslashes that Windows users are used to. I found that this was necessary for the kernel to work &#8211;it was ignored by the notebook otherwise.<\/p>\n<p><strong>Finishing off<\/strong><\/p>\n<p>Everything created so far, including R, is in the folder <strong>Portable Python 2.7.6<\/strong><\/p>\n<p>I created a folder called <strong>PortableJupyter<\/strong>\u00a0and put the <strong>Portable Python 2.7.6<\/strong> folder inside it. I also created the folder <strong>PortableJupyter\\notebooks<\/strong>\u00a0to allow me to carry my notebooks around with the software that runs them.<\/p>\n<p>There is a bug in Portable Python 2.7.6.1 relating to scripts like IPython.exe that have been installed using easy_install. In short, they stop working if you move the directory they&#8217;re installed in &#8211; breaking portability somewhat! (<a href=\"https:\/\/groups.google.com\/forum\/#!searchin\/portablepython\/ipython%7Csort:date\/portablepython\/mKOJHAlPYjM\/DF-ZAo-H-JsJ\">Details here<\/a>)<\/p>\n<p>The workaround is to launch Ipython by running the script <strong>Portable Python 2.7.6.1\\App\\Scripts\\ipython-script.py<\/strong><\/p>\n<p>I didn&#8217;t want to bother with that so created a shortcut in my <strong>PortableJupyter<\/strong> folder called <strong>Launch notebook.<\/strong> The target of this shortcut was the following line<\/p>\n<div style=\"width:750px;word-wrap: break-word;\">\n<pre>%windir%\\system32\\cmd.exe \/c \"cd notebooks &amp;&amp; \"%CD%\/Portable Python 2.7.6.1\/App\\python.exe\" \"%CD%\/Portable Python 2.7.6.1\\App\\Scripts\\ipython-script.py\" notebook\"<\/pre>\n<\/div>\n<p>This starts the notebook using the default web browser and puts you in the notebooks directory.<\/p>\n<p><strong>The pay off<\/strong><\/p>\n<p>My folder looks like this:<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_folder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5739\" alt=\"PortableJupyter_folder\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_folder.png\" width=\"817\" height=\"432\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_folder.png 817w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_folder-300x158.png 300w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/a><\/p>\n<p>If I click on the Launch Notebook shortcut, I get a Jupyter session with 2 kernel options<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_kernels.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5740\" alt=\"PortableJupyter_kernels\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_kernels.png\" width=\"341\" height=\"266\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_kernels.png 341w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_kernels-300x234.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/a><\/p>\n<p>I can choose the Portable R kernel and start using R in the notebook!<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_screenshot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5741\" alt=\"PortableJupyter_screenshot\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_screenshot.png\" width=\"697\" height=\"377\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_screenshot.png 697w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/04\/PortableJupyter_screenshot-300x162.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently found myself in need of a portable install of the Jupyter notebook which made use of a portable install of R as the compute kernel. When you work in institutions that have locked-down managed Windows desktops, such portable installs can be a life-saver! This is particularly true when you are working with rapidly [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[40,31,36,67,69,66],"tags":[],"class_list":["post-5734","post","type-post","status-publish","format-standard","hentry","category-free-software","category-python","category-r","category-scientific-software","category-software-deployment","category-windows"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1uu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5734"}],"version-history":[{"count":28,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5734\/revisions"}],"predecessor-version":[{"id":5767,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5734\/revisions\/5767"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}