cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
Update (3 January 2016): In order to build OpenCV
3.1.0 , you need to set
-D INSTALL_C_EXAMPLES=OFF (rather than
ON ) in the
cmake
command. There is a bug in the OpenCV v3.1.0 CMake build script that
can cause errors if you leave this switch on. Once you set this switch
to off, CMake should run without a problem.
Now we can finally compile OpenCV:
$ make -j4
Where you can replace the 4 with the number of available cores on your processor to speedup the compilation.
Installing Supporting Packages:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook
python-pandas python-sympy python-nose
List of Support Packages available for python:
FAQ
Package installation
There are two standard methods for installing a package.
pip install
The
pip install script is available within our scientific Python
installation and is very easy to use (when it works). During the installation
process you already saw many examples of
pip install in action. Features include:
- If supplied with a package name then it will query the PyPI site to find out about
that package. Assuming the package is there then pip install will
automatically download and install the package.
- Will accept a local tar file (assuming it contains an installable Python package) or a URL
pointing to a tar file.
- Can install in the user package area via pip install <package or URL>
--user (but see discussion further down)
python setup.py install
Some packages may fail to install via
pip install. Most often there will
be some obvious (or not) error message about compilation or missing
dependency. In this case the likely next step is to download the installation tar
file and untar it. Go into the package directory and look for files like:
INSTALL
README
setup.py
setup.cfg
If there is an INSTALL or README file then hopefully you will find useful
installation instructions. Most well-behaved python packages do the
installation via a standard
setup.py script. This is used as follows:
python setup.py --help # get options
python setup.py install # install in the python area (root / admin req'd)
python setup.py install --user # install to user's package area
Where do packages get installed?
An important option in the installation process is where to put the package
files. We’ve seen the
--user option in
pip install and
python
setup.py install. What’s up with that? In the section below we document
how this works. See the discussion in
Multiple Pythons on
your computer for a reason you might want to do this, but first please read
this warning:
Warning
We strongly recommend against installing packages with --user unless you
are an expert and really understand what you are doing, . This is because
the local user version will always take precedence and can thus potentially
disrupt other Python installations and cause hard-to-understand problems.
Big analysis packages like CIAO, STSci_Python or CASA are carefully tested
assuming the integrated environment they provide. If you start mucking this
up then all bets are off.
WITH --user
Packages get installed in a local user-owned directory when you do something
like either of the following:
pip install --user aplpy
python setup.py install --user
This puts the packages into:
Mac |
~/Library/Python/2.x/lib/python/site-packages |
Linux |
~/.local/lib/python-2.x/site-packages |
Windows |
%APPDATA%/Python/Python2x/site-packages |
WITHOUT --user
If you use Anaconda or a non-root Python installation then there is no issue
with permissions on any platform since the entire installation is local to a
directory you own.
However, installing to a system-wide Python installation will require root or
admin privilege. Installing this way has the benefit of making the package
available for all users of the Python installation, but has the downside
that
it is more difficult to back out changes if required. In general we recommend
using
only the system package manager (e.g.
yum) to install packages to
the system Python. This will ensure integrity of your system Python, which is
important even if you are the only user.
How do I find a package once installed?
Finding the file associated with a package or module is simple, just use the
help
command in IPython:
Where does Python look for modules?
The official reference on
Modifying Python’s Search Path
gives all the details. In summary:
When the Python interpreter executes an import statement, it looks for modules
on a search path. A default value for the path is configured into the Python
binary when the interpreter is built. You can determine the path by importing
the
sys module and
printing the value of
sys.path:
$ python
Python 2.2 (#11, Oct 3 2002, 13:31:27)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
'/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',
'/usr/local/lib/python2.3/site-packages']
>>>
Within a script it is possible to adjust the search path by modify
sys.path
which is just a Python list. Generally speaking you will want to put your path
at the front of the list using insert:
import sys
sys.path.insert(0, '/my/path/python/packages')
You can also add paths to the search path using the
PYTHONPATH environment variable.
No comments:
Post a Comment