Add next and previous navigation links to all tutorials
[platform/upstream/opencv.git] / doc / tutorials / introduction / macos_install / macos_install.markdown
1 Installation in MacOS {#tutorial_macos_install}
2 =====================
3
4 @prev_tutorial{tutorial_android_ocl_intro}
5 @next_tutorial{tutorial_ios_install}
6
7
8 The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well.
9
10 Required Packages
11 -----------------
12
13 -   CMake 3.9 or higher
14 -   Git
15 -   Python 2.7 or later and Numpy 1.5 or later
16
17 This tutorial will assume you have [Python](https://docs.python.org/3/using/mac.html),
18 [Numpy](https://docs.scipy.org/doc/numpy-1.10.1/user/install.html) and
19 [Git](https://www.atlassian.com/git/tutorials/install-git) installed on your machine.
20
21 @note
22 OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically.
23
24 @note
25 If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine.
26
27 Installing CMake
28 ----------------
29 -# Find the version for your system and download CMake from their release's [page](https://cmake.org/download/)
30
31 -# Install the dmg package and launch it from Applications. That will give you the UI app of CMake
32
33 -# From the CMake app window, choose menu Tools --> Install For Command Line Use.
34
35 -# Install folder will be /usr/bin/ by default, submit it by choosing Install command line links.
36
37 -# Test that it works by running
38     @code{.bash}
39     cmake --version
40     @endcode
41
42 Getting OpenCV Source Code
43 --------------------------
44
45 You can use the latest stable OpenCV version or you can grab the latest snapshot from our
46 [Git repository](https://github.com/opencv/opencv.git).
47
48 ### Getting the Latest Stable OpenCV Version
49
50 -   Go to our [downloads page](http://opencv.org/releases.html).
51 -   Download the source archive and unpack it.
52
53 ### Getting the Cutting-edge OpenCV from the Git Repository
54
55 Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv).
56 If you need modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
57
58 For example
59 @code{.bash}
60 cd ~/<my_working_directory>
61 git clone https://github.com/opencv/opencv.git
62 git clone https://github.com/opencv/opencv_contrib.git
63 @endcode
64 Building OpenCV from Source Using CMake
65 ---------------------------------------
66
67 -#  Create a temporary directory, which we denote as `<cmake_build_dir>`, where you want to put
68     the generated Makefiles, project files as well the object files and output binaries and enter
69     there.
70
71     For example
72     @code{.bash}
73     mkdir build_opencv
74     cd build_opencv
75     @endcode
76
77     @note It is good practice to keep clean your source code directories. Create build directory outside of source tree.
78
79 -#  Configuring. Run `cmake [<some optional parameters>] <path to the OpenCV source directory>`
80
81     For example
82     @code{.bash}
83     cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv
84     @endcode
85
86     or cmake-gui
87
88     -   set full path to OpenCV source code, e.g. `/home/user/opencv`
89     -   set full path to `<cmake_build_dir>`, e.g. `/home/user/build_opencv`
90     -   set optional parameters
91     -   run: "Configure"
92     -   run: "Generate"
93
94 -#  Description of some parameters
95     -   build type: `CMAKE_BUILD_TYPE=Release` (or `Debug`)
96     -   to build with modules from opencv_contrib set `OPENCV_EXTRA_MODULES_PATH` to `<path to
97         opencv_contrib>/modules`
98     -   set `BUILD_DOCS=ON` for building documents (doxygen is required)
99     -   set `BUILD_EXAMPLES=ON` to build all examples
100
101 -#  [optional] Building python. Set the following python parameters:
102     -   `PYTHON3_EXECUTABLE = <path to python>`
103     -   `PYTHON3_INCLUDE_DIR = /usr/include/python<version>`
104     -   `PYTHON3_NUMPY_INCLUDE_DIRS =
105         /usr/lib/python<version>/dist-packages/numpy/core/include/`
106     @note
107     To specify Python2 versions, you can replace `PYTHON3_` with `PYTHON2_` in the above parameters.
108
109 -#  Build. From build directory execute *make*, it is recommended to do this in several threads
110
111     For example
112     @code{.bash}
113     make -j7 # runs 7 jobs in parallel
114     @endcode
115
116 -#  To use OpenCV in your CMake-based projects through `find_package(OpenCV)` specify `OpenCV_DIR=<path_to_build_or_install_directory>` variable.
117
118 @note
119 You can also use a package manager like [Homebrew](https://brew.sh/)
120 or [pip](https://pip.pypa.io/en/stable/) to install releases of OpenCV only (Not the cutting edge).