Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dat-boris/f05e443ea74abd86c08c64c715ca839f to your computer and use it in GitHub Desktop.
Save dat-boris/f05e443ea74abd86c08c64c715ca839f to your computer and use it in GitHub Desktop.
Paperspace tensorflow+opencv setup for both python2 and python3 on ubuntu 16
#!/bin/bash -xe
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Stuff for making stuff
sudo apt-get update
sudo apt-get install -y build-essential gcc checkinstall cmake pkg-config git unzip wget gdb
# pre-install cuda
sudo apt -y install python3-pip install nvidia-cuda-dev
# Download some nvidia stuff
# http://www.nvidia.com/content/DriverDownload-March2009/confirmation.php?url=/XFree86/Linux-x86_64/375.39/NVIDIA-Linux-x86_64-375.39.run&lang=us&type=GeForce
# https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod_20161129/8.0/cudnn-8.0-linux-x64-v5.1-tgz
# https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
wget --no-check-certificate 'https://www.dropbox.com/s/tum2c4icovkob4o/paperspace_download.tgz'
tar xzf paperspace_download.tgz
mv paperspace_download/* .
# # Install the drivers
# # make sure you say yes to gl and to linking to /usr/local
# chmod a+x NVIDIA-Linux-x86_64-375.39.run
# sudo ./NVIDIA-Linux-x86_64-375.39.run
# Install CUDA
# say NO to installing the drivers!
chmod a+x cuda_8.0.61_375.26_linux-run
sudo ./cuda_8.0.61_375.26_linux-run
# Install CUDNN
tar -xvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp -P include/cudnn.h /usr/include
sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/
sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*
sudo cp include/cudnn.h /usr/local/cuda-8.0/include
sudo cp lib64/libcudnn* /usr/local/cuda-8.0/lib64
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
sudo ldconfig
# reinstall tensorflow
sudo pip3 install --upgrade tensorflow
# https://stackoverflow.com/questions/43558707/tensorflow-importerror-libcusolver-so-8-0-cannot-open-shared-object-file-no
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
# Optional in case of error
# ldconfig /usr/local/cuda-8.0/lib64
# ldconfig /usr/lib/x86_64-linux-gnu
##########
# Below is removed
# # Add bazel repo
# echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
# curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
# sudo apt-get update
# # Remove existing old crap
# sudo apt-get autoremove -y libopencv-dev python-opencv
# # Some Libs
# sudo apt-get install -y openjdk-8-jdk git python-dev python3-dev python-numpy python3-numpy python-six python3-six build-essential python-pip python3-pip python-virtualenv swig python-wheel python3-wheel libcurl3-dev libcupti-dev
# sudo cp cuda/include/cudnn.h /usr/local/cuda/include
# sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
# sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# # Some libs
# # libgoogle-glog-dev
# sudo apt-get install -y qt5-default qt5-qmake libvtk6-dev tcl-vtk libxmu-dev liblapack-dev liblapacke liblmdb-dev libgflags-dev
# sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libatlas-base-dev openjdk-8-jdk libcurl3-dev libcupti-dev swig
# # Python shtuff
# sudo apt-get install -y python-pip
# pip install --upgrade pip
# pip install numpy
# sudo apt-get install -y python3-pip
# pip3 install --upgrade pip
# pip3 install numpy
# # Media I/O:
# sudo apt-get install -y zlib1g-dev libjpeg-dev libjpeg8-dev libwebp-dev libpng-dev libpng12-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev
# # Video I/O:
# sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev
# # Math libraries:
# sudo apt-get install -y gfortran libtbb-dev libeigen3-dev libleveldb-dev libsnappy-dev libboost-dev libhdf5-dev
# # libprotobuf-dev
# # Java:
# sudo apt-get install -y ant default-jdk
# # Documentation:
# sudo apt-get install -y doxygen
# # Install bazel
# sudo apt-get install -y bazel
# sudo apt-get upgrade bazel
# # INSTALL OPENCV
# wget https://github.com/opencv/opencv/archive/3.2.0.zip
# unzip 3.2.0.zip
# rm 3.2.0.zip
# #mv opencv-3.2.0 OpenCV
# cd opencv-3.2.0
# mkdir build
# cd build
# cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON ..
# make -j4
# sudo make install
# sudo ldconfig
# # TEST CV2 (these should both print out 3.2.0)
# cd ~/
# python -c 'import cv2;print(cv2.__version__)'
# python3 -c 'import cv2;print(cv2.__version__)'
# # Install python packages
# sudo pip install scipy numpy matplotlib ipython jupyter pandas sympy nose pillow scikit-learn statsmodels
# sudo pip3 install scipy numpy matplotlib ipython jupyter pandas sympy nose pillow scikit-learn statsmodels
# # Jupyter notebook bind to 0.0.0.0 by default
# mkdir ~/.jupyter
# touch ~/.jupyter/jupyter_notebook_config.py
# echo "c.NotebookApp.ip = '0.0.0.0'" | sudo tee -a ~/.jupyter/jupyter_notebook_config.py
# echo "c.ConnectionFileMixin.ip = '0.0.0.0'" | sudo tee -a ~/.jupyter/jupyter_notebook_config.py
# # Installing tensorflow!
# # COMPUTE CAPABILITY IS 6.1
# cd ~/
# wget https://github.com/tensorflow/tensorflow/archive/v1.1.0.zip
# unzip v1.1.0.zip
# rm v1.1.0.zip
# mv tensorflow-1.1.0 tensorflow-1.1.0_py2
# cp -rd tensorflow-1.1.0_py2 tensorflow-1.1.0_py3
# # Tensorflow Python 2:
# # COMPUTE CAPABILITY IS 6.1
# cd ~/tensorflow-1.1.0_py2
# ./configure
# # May need to add ``, don't remember
# bazel build --config=opt --copt=-march=native --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -k //tensorflow/tools/pip_package:build_pip_package
# mkdir pip_build
# bazel-bin/tensorflow/tools/pip_package/build_pip_package `pwd`/pip_build
# cd pip_build
# sudo pip install tensorflow*
# cd ~/
# python -c 'import tensorflow as tf;hello=tf.constant("Hello, TensorFlow!");sess=tf.Session();print(sess.run(hello))'
# # Tensorflow Python 3:
# # COMPUTE CAPABILITY IS 6.1
# # When configuring, make sure you set the python to python3 when asked: /usr/bin/python3
# cd ~/tensorflow-1.1.0_py3
# ./configure
# bazel build --config=opt --copt=-march=native --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -k //tensorflow/tools/pip_package:build_pip_package
# mkdir pip_build
# bazel-bin/tensorflow/tools/pip_package/build_pip_package `pwd`/pip_build
# cd pip_build
# sudo pip3 install tensorflow*
# cd ~/
# python3 -c 'import tensorflow as tf;hello=tf.constant("Hello, TensorFlow!");sess=tf.Session();print(sess.run(hello))'
# # Assuming the above worked, let's clean up after ourselves:
# cd ~/
# mkdir setup_stuff
# sudo rm -rdf cuda
# mv tensorflow* setup_stuff
# mv tensorflow* setup_stuff
# mv cud* setup_stuff
# mv NVIDIA-Linux* setup_stuff
# mv opencv* setup_stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment