Setting up python 3.5 dev env in Ubuntu

Post date: Jul 14, 2016 11:37:0 PM

The goal is to setup a python environment for scientific computing: matplotlib, numpy, scipy, scikit, tensorflow.

# basic packages, using python3-dev to avoid fatal error: Python.h: No such file or directory [2]

sudo apt-get install python-virtualenv python-pip python3-dev python-dev

# virtual environment

virtualenv -p python3.5 ~/env3.5

source ~/env3.5/bin/activate

python -c 'import ctypes' # avoid python 3.4.0, which has a bug in importing ctypes [1], this is fixed in 3.4.3

# matplotlib, numpy

sudo apt-get install libfreetype6-dev

sudo apt-get install pkg-config

sudo apt-get install tk-dev # see [3]

sudo apt-get install python3-tk

pip install numpy

pip install -U matplotlib

python -c 'import matplotlib.pyplot'

python -c 'import matplotlib; matplotlib.matplotlib_fname()' # see [4]

python -c 'import matplotlib; import matplotlib.pyplot; print(matplotlib.backends.backend)'

# scipy

sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran # see [5]

pip install -U scipy

# scikit

pip install -U scikit-learn

# jupyter for bash in Windows, see [6]

pip uninstall pyzmq

sudo add-apt-repository ppa:aseering/wsl

sudo apt-get update

sudo apt-get install libzmq3 libzmq3-dev

export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

pip install --no-use-wheel -v pyzmq

pip install jupyter

# jupyter for bash in Ubuntu 14.04 and python 3

git clone https://github.com/jupyter-widgets/ipywidgets

cd ipywidgets

pip install .

pip install jupyter

# jupyter for bash in Ubuntu 14.04 and python 2

pip install --upgrade pip # upgrade pip, see [10]

pip -V # verify pip version

pip install jupyter

# to start

jupyter notebook 

# opencv

Most likely have to build from source, follow the instructions in [7]

See [8] for "Issue: ImportError: libopencv_ccalib.so.3.1: cannot enable executable stack as shared object requires: Invalid argument"

sudo apt-get install execstack

sudo execstack -c /usr/local/lib/libopencv_*

See [9] for "libdc1394 error: Failed to initialize libdc1394"

sudo ln /dev/null /dev/raw1394

# tensorflow

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl # CPU

lspci | grep VGA # check VGA compute capability

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl # GPU

pip install -U $TF_BINARY_URL

#tflearn

sudo apt-get install libhdf5-dev

pip install h5py

pip install -U tflearn # stable version

pip install git+https://github.com/tflearn/tflearn.git #  bleeding edge version

[1] http://stackoverflow.com/questions/33223713/python-ctypes-import-error-in-virtualenv

[2] http://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory

[3] http://stackoverflow.com/questions/32188180/from-matplotlib-backends-import-tkagg-importerror-cannot-import-name-tkagg

[4] http://stackoverflow.com/questions/14558843/why-matplotlib-does-not-plot

[5] https://stackoverflow.com/questions/11114225/installing-scipy-and-numpy-using-pip/31840553#31840553

[6] https://github.com/jupyter/notebook/issues/1331

[7] http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/

[8] https://stackoverflow.com/questions/39136040/python3-4-error-cannot-enable-executable-stack-as-shared-object-requires-inva

[9] https://stackoverflow.com/questions/12689304/ctypes-error-libdc1394-error-failed-to-initialize-libdc1394

[10] https://stackoverflow.com/questions/28502283/valueerror-expected-version-spec-when-installing-local-wheel-via-pip