- Machine Learning for OpenCV
- Michael Beyeler
- 509字
- 2025-04-04 18:50:48
Getting to grips with Python's Anaconda distribution
Anaconda is a free Python distribution developed by Continuum Analytics that is made for scientific computing. It works across Windows, Linux, and Mac OS X platforms and is free even for commercial use. However, the best thing about it is that it comes with a number of preinstalled packages that are essential for data science, math, and engineering. These packages include the following:
- NumPy: A fundamental package for scientific computing in Python, which provides functionality for multidimensional arrays, high-level mathematical functions, and pseudo-random number generators
- SciPy: A collection of functions for scientific computing in Python, which provides advanced linear algebra routines, mathematical function optimization, signal processing, and so on
- scikit-learn: An open-source machine learning library in Python, which provides useful helper functions and infrastructure that OpenCV lacks
- Matplotlib: The primary scientific plotting library in Python, which provides functionality for producing line charts, histograms, scatter plots, and so on
- Jupyter Notebook: An interactive environment for the running of code in a web browser
An installer for our platform of choice (Windows, Mac OS X, or Linux) can be found on the Continuum website, https://www.continuum.io/Downloads. I recommend using the Python 3.6-based distribution, as Python 2 is no longer under active development.
To run the installer, do one of the following:
- On Windows, double-click on the .exe file and follow the instructions on the screen
- On Mac OS X, double-click on the .pkg file and follow the instructions on the screen
- On Linux, open a terminal and run the .sh script using bash:
$ bash Anaconda3-4.3.0-Linux-x86_64.sh # Python 3.6 based
$ bash Anaconda2-4.3.0-Linux-x64_64.sh # Python 2.7 based
In addition, Python Anaconda comes with conda--a simple package manager similar to apt-get on Linux. After successful installation, we can install new packages in the terminal using the following command:
$ conda install package_name
Here, package_name is the actual name of the package that we want to install.
Existing packages can be updated using the following command:
$ conda update package_name
We can also search for packages using the following command:
$ anaconda search -t conda package_name
This will bring up a whole list of packages available through individual users. For example, searching for a package named opencv, we get the following hits:

This will bring up a long list of users who have OpenCV packages installed, where we can locate users that have our version of the software installed on our own platform. A package called package_name from a user called user_name can then be installed as follows:
$ conda install -c user_name package_name
Finally, conda provides something called an environment, which allows us to manage different versions of Python and/or packages installed in them. This means we could have one environment where we have all packages necessary to run OpenCV 2.4 with Python 2.7, and another where we run OpenCV 3.2 with Python 3.6. In the following section, we will create an environment that contains all the packages needed to run the code in this book.