{"id":1708,"date":"2015-05-30T16:24:23","date_gmt":"2015-05-30T23:24:23","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=1708"},"modified":"2015-06-01T16:10:33","modified_gmt":"2015-06-01T23:10:33","slug":"bash-script-to-install-python-locally-without-root-permissions","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=1708","title":{"rendered":"Bash script to install python locally without root permissions"},"content":{"rendered":"<p>This bash script  downloads, builds and installs a particular version of python in the location of your choice without requiring root permissions. It also creates a virtual environment that you can activate to use it. It is licensed under the terms of MIT open source license.<\/p>\n<div style=\"margin-left: 20px; margin-right: 20px; padding: 5px; background: #ffffdb;\">\nThis script is also available on github: <a href=\"https:\/\/github.com\/jlinoff\/pybld.git\">https:\/\/github.com\/jlinoff\/pybld.git<\/a>\n<\/div>\n<p><!--more--><\/p>\n<p>This script makes it easy to install multiple versions of python for staging tests (i.e., tests that you would want to run before installing the new version into production).<\/p>\n<p>You can download it from <a href=\"http:\/\/projects.joelinoff.com\/pybld\/pybld.sh\">http:\/\/projects.joelinoff.com\/pybld\/pybld.sh<\/a>.<\/p>\n<p>I have only tested it on CentOS linux and Mac OS X.<\/p>\n<p>Here is how you would download and run it for a very simple case.<\/p>\n<pre class=\"theme:vs2012-black font-size:12 line-height:17 lang:bash decode:true\">\r\n$ mkdir -p ~\/work\/python\/2.7.10\r\n$ cd ~\/work\/python\/2.7.10\r\n$ wget http:\/\/projects.joelinoff.com\/pybld\/pybld.sh\r\n$ chmod a+x pybld.sh\r\n$ (time .\/pybld.sh -v 2.7.10) 2>&1 | tee log\r\n&lt;output snipped&gt;\r\n\r\n$ # Now run it in the virtual environment.\r\n$ rtf\/venv\/python2710\/bin\/activate\r\n$ python --version\r\nPython 2.7.10\r\n$ pip install pycrypto\r\n&lt;output snipped&gt;\r\n$ pip install netaddr\r\n&lt;output snipped&gt;\r\n\r\n$ python\r\n&lt;header snipped&gt;\r\n>>> import Crypto\r\n>>> import netaddr\r\n>>> quit()\r\n<\/pre>\n<p>The script has the following options.<\/p>\n<table>\n<thead>\n<tr>\n<th>Long<br \/>Option<\/th>\n<th>Short<br \/>Option<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&#8211;build-dir &lt;dir&gt;<\/td>\n<td>-b &lt;dir&gt;<\/td>\n<td>The build directory. It can be deleted after successfully installing python.<\/td>\n<\/tr>\n<tr>\n<td>&#8211;help<\/td>\n<td>-h<\/td>\n<td>This help message.<\/td>\n<\/tr>\n<tr>\n<td>&#8211;release-dir &lt;dir&gt;<\/td>\n<td>-r &lt;dir&gt;<\/td>\n<td>The release directory (contains bin\/python).<\/td>\n<\/tr>\n<tr>\n<td>&#8211;test<\/td>\n<td>-t<\/td>\n<td>Test the installation. Be careful, this substantially increases the installation time and may result in false positives.<\/td>\n<\/tr>\n<tr>\n<td>&#8211;venv-dir &lt;dir&gt;<\/td>\n<td>-e &lt;dir&gt;<\/td>\n<td>The virtualenv directory (contains bin\/activate).<\/td>\n<\/tr>\n<tr>\n<td>&#8211;version &lt;version&gt;<\/td>\n<td>-v &lt;version&gt;<\/td>\n<td>The python version to install. An example would be &#8220;2.7.10&#8221;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This bash script downloads, builds and installs a particular version of python in the location of your choice without requiring root permissions. It also creates a virtual environment that you can activate to use it. It is licensed under the terms of MIT open source license. This script is also available on github: https:\/\/github.com\/jlinoff\/pybld.git<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[15,7,16],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1708"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1708"}],"version-history":[{"count":17,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1708\/revisions"}],"predecessor-version":[{"id":1725,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1708\/revisions\/1725"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}