|
||
Website deprecated and outdated. Click here for the new site. | ||
Dept. of Computer Sc. » Pattern Recognition » Courses » WS 17/18 » Introduction to Pattern Recognition [IntroPR] » Python installation
Python installationNOTE Due to legal reasons, this is NOT a recommendation of what software you should install on your computer! This is just a report of what software I installed on my own computer to execute the Python examples shown in this course. The fact that it worked for me on my Microsoft Windows 10 (64 bit) machine and on my Ubuntu 16.04 LTS (64 bit) machine does not mean that it will work for you on your computer, too. Depending on your hardware and the operating system that you use, you might have to install different software or packages, e.g. 32 bit versions. This report is of August 2016; things might have changed since then. We actually recommend:
Python 2 vs. Python 3¶Currently, there are two Python branches that are being actively developed: Python 2 and Python 3. The latest version of Python 3 is Python 3.5.x; the latest version of Python 2 is Python 2.7.x. Although Python 3 is the more modern one, there are still Python extension packages that are only available for Python 2. The examples given in this course are based on Python 3.5 and use the new Python 3 syntax. As stated above, Python 3 comes with a new syntax. However, if you prefer to work with Python 2, you can force Python 2 to use this new syntax by including the following, so-called "future" packages: In [ ]:
from __future__ import absolute_import, division, print_function
Microsoft Windows 10 (64 bit)¶Assuming that you have a recent version of Windows and enough free disk space, things are rather simple. Similar to LaTeX there are different distributions for Python which differ in the number of Python extension packages that are included and consequently in the disk space that is required for installation. A distribution that already includes many Python packages is Anaconda, which is available here: https://www.continuum.io/downloads. In order to install Anaconda 4.1.1, I downloaded the 64 BIT INSTALLER (351 MB) for Python 3.5: Anaconda3-4.1.1-Windows-x86_64.exe. Installing missing Python extension packages from source code¶Although Anaconda comes with many Python extension packages, some packages that we will use in this course are missing. However, they can be easily installed from the Python source code repository by simply executing the following commands on the Windows command line: In [ ]:
pip install py-cpuinfo
pip install urllib3
Installing missing pre-compiled Python extension packages ('wheels')¶Other missing extension packages (such as OpenCV) are large and have many dependencies; it is easier to install so-called pre-compiled 'wheels'. Christoph Gohlke from the University of California, Irvine, CA, U.S.A., provides up-to-date executables for many Python extension packages on his website: http://www.lfd.uci.edu/~gohlke/pythonlibs/. After downloading the wheels, they can be installed on the Windows command line using pip again: In [ ]:
pip install opencv_python-3.1.0-cp35-cp35m-win_amd64.whl
pip install PyWavelets-0.4.0-cp35-none-win_amd64.whl
pip install cvxopt-1.1.7-cp35-none-win_amd64.whl
You should now be able to execute your own Python programs and the Python examples provided in our tutorials. You should even be able to execute our Jupyter notebooks available at the IntroPR website. Download the notebooks, switch to the Windows command line, change the directory to the one where you downloaded the notebooks, and execute: In [ ]:
jupyter.exe notebook
Ubuntu 16.04 LTS (64 bit)¶There are many different Linux distributions. I decided for Ubuntu as it is user-friendly and has a very large community, which is certainly an advantage if one is looking for help. The latest Ubuntu version with long term support (LTS) is Ubuntu 16.04 LTS. This Linux distribution offers packages for both Python 2 and Python 3. They can be installed using apt. At the time when I installed my Python environment, unfortunately no Ubuntu package was available for the Python bindings of OpenCV. You can either decide to use Python 2 or compile OpenCV 3 for Python 3 on your own, which requires some expert knowledge if things do not work as described in existing tutorials. Check the available packages for Python 3 using In [ ]:
apt-cache search python3
Installing pre-compiled Python 3 packages¶On a new Ubuntu 16.04 LTS installation, I had to install to following Python 3 packages: In [ ]:
sudo apt install libblas-dev
sudo apt install liblapack-dev
sudo apt install python3-numpy
sudo apt install python3-scipy
sudo apt install python3-pyqt4 # for our master's degree course Pattern Recognition
sudo apt install python3-matplotlib
sudo apt install python3-sklearn
sudo apt install python3-skimage
sudo apt install python3-pip
Installing missing Python 3 extension packges from source code¶Furthermore, I had to install the following Python 3 packages from source code: In [ ]:
sudo pip3 install cvxopt
sudo pip3 install pywavelets
sudo pip3 install py-cpuinfo
sudo pip3 install py-jupyter
You now can execute our Python examples and run our jupyter notebooks (except the ones using OpenCV). To run the jupyter notebooks of our tutorials, download them, start a terminal session, switch to the directory where you downloaded the jupyter notebooks, and execute In [ ]:
jupyter notebook
NOTE Be aware that there are some critical security issues, if you run a jupyter notebook server on a multi-user system as in the standard configuration, the access to the jupyter server is not password protected. Any local user has access to your jupyter server and can execute
A good tutorial can be found here:
http://jupyter-notebook.readthedocs.io/en/latest/public_server.html. Compiling OpenCV 3.1.0 for Python 3.5¶Basically, I followed the instructions of the following tutorial and made some minor adaptations for Python 3.5 and some simplifications: http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/. Get the latest list of packages and update your system before you proceed: In [ ]:
sudo apt-get updade
sudo apt-get upgrade
Install the following required packages: In [ ]:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3.5-dev
Checkout OpenCV 3.1, compile and install it: In [ ]:
cd ~
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.1.0
cd ~
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.1.0
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
Eclipse¶There are many integrated development environments (IDEs) that can be used for Python programming. One of them is Eclipse. We stick to this IDE as most of the IntroPR and PR students are already familar with this IDE.
The latest version of Eclipse is Eclipse Neon. It is available from http://www.eclipse.org/downloads. In order to install Eclipse Neon for Windows 10 (64 bit), I downloaded eclipse-inst-win64.exe. In many cases, Eclipse for Linux can be installed easily using the software installation tool of the Linux distribution. PyDev¶In order to use Eclipse for Python programming, I installed PyDev: following the instructions from their manual: |