Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Isolated Python 3 (from source) with Scientific Stack in a Virtual-Environment (double isolation) on Ubuntu Precise (As of Feb 2014)
# - Code is provided "as is" and any expressed or implied warranties are disclaimed.
# - Errors and omissions excepted.
# - Read it carefully, some commands might have to be changed for your system.
# - BLAS/LAPACK compilation commands will most likely have to be changed based on the
# stackoverflow link below.
# - Running this shell file as a script is NOT recommended. Copy/pasting one command at a time is
# okay as long as you monitor the output for any possible errors/warnings.
# - If you face errors at any step, then after you fix your errors, you might have to repeat the
# previous few steps before you continue. (e.g., if make fails, I would fix the issue, delete the
# untarred Python directory and untar and configure again. It's a bit of a hassle, and may be
# unnecessary, but gives peace of mind). It's a judgement call.
# - If you know what you're doing, feel free to customize it, e.g., changing names of directories
# etc.
# This sequence of commands, with appropriate modifications, will create a Python 3 installation in
# your home directory, isolated from Ubuntu's built-in python installation. It will then create
# a virtual environment for your scientific stack, in which it will install the scientific stack
# (including python itself) and the pip system that will allow you to install more packages in the
# future. This method is up-to-date as of Feb 2014 to the best of my knowledge.
# Rationale for doing this:
# Install pre-requisite packages (hopefully these should be enough!)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev libc6-dev
sudo apt-get install libgdbm-dev lzma-dev liblzma-dev tk-dev
sudo apt-get install libfreetype6-dev libpng12-dev
sudo apt-get install libzmq-dev libzmq1 libzmq-dbg
sudo apt-get install libssl-dev libreadline-dev libncursesw5-dev
sudo apt-get install gfortran
# You don't need 'sudo' beyond this point!
# Create a separate directory for the build work (recommended)
mkdir $HOME/python3-build-work
cd $HOME/python3-build-work
# Download and install Python-3.3.4
tar xf Python-3.3.4.tar.xz
cd Python-3.3.4
CXX=g++ ./configure --prefix=$HOME/opt/python-3.3.4
make install
# Create shortcuts in $HOME/bin directory (create this directory if you don't have it)
cd $HOME/bin
ln -s $HOME/opt/python-3.3.4/bin/python3.3 python3
# You may have to restart terminal at this point (or source $HOME/.bashrc or something)
# Test your python3 installation (it should work at this point)
which python3
# Download and install setuptools (ez_setup), pip, and virtualenv
cd $HOME/python3-build-work
cd $HOME/bin
ln -s $HOME/opt/python-3.3.4/bin/easy_install-3.3 easy_install3
easy_install3 pip
ln -s $HOME/opt/python-3.3.4/bin/pip3.3 pip3
pip3 install virtualenv
ln -s $HOME/opt/python-3.3.4/bin/virtualenv virtualenv3
ln -s $HOME/opt/python-3.3.4/bin/pyvenv-3.3 pyvenv3
# Create another directory for your virtual environments
mkdir $HOME/python3VEs
cd $HOME/python3VEs
# Create and enter the virtual environment for the scientific stack
virtualenv3 scientificstack3
source scientificstack3/bin/activate
which python
which pip
# Install numpy
pip install numpy
# Download and compile BLAS (note: you may have to use a different gfortran command)
# See the answer and comments in this link for details:
cd $HOME/python3-build-work
tar xf blas.tgz
gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f
ar r libfblas.a *.o
ranlib libfblas.a
rm -rf *.o
cd ..
# Download and compile LAPACK (note: you may have to edit for compile flags)
# See the answer and comments in this link for details:
tar xf lapack.tgz
cd lapack-3.5.0
make lapacklib
make clean
# Install scipy
export BLAS=$HOME/python3-build-work/BLAS/libfblas.a
export LAPACK=$HOME/python3-build-work/lapack-3.5.0/liblapack.a
pip install scipy
# Install the rest of the scientific stack (or more if you want)
pip install nose
pip install tornado
pip install matplotlib
pip install pyzmq
pip install jinja2
pip install ipython
pip install pandas
pip install sympy
pip install pygments
pip install networkx
pip install quantities
pip install rpy2
pip install scikit-learn
pip install numba
# Test your shiny ipython3 install (it should open a url in browser:
ipython3 notebook --pylab inline
# Exit the scientific stack virtual environment
# Note:
# - To uninstall the whole scientific stack but not python3, just delete $HOME/python3VEs/scientificstack3
# - To uninstall python3 as well, delete $HOME/opt/python-3.3.4 (and the soft links in $HOME/bin)
# - python3-build-work is a temporary directory and can be deleted as soon as you are done with the
# installation process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment