# 安裝 OpenCV (Ubuntu 16.04)
> [轉載網址](https://askubuntu.com/questions/783956/how-to-install-opencv-3-1-for-python-3-5-on-ubuntu-16-04-lts)
> [name=謝朋諺]
###### tags: `Environment`
現在只要這樣安裝就可以了!
```
apt install -y ffmpeg libsm6 libxext6
pip install opencv-python
```
---
1. Update the repository:
```shell=
sudo apt-get update
```
---
2. Download the required packages to compile OpenCV:
```shell=
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
```
---
3. Install the developer packages for Python3.5:
```shell=
sudo apt-get install python3.5-dev
```
---
4. Copy the dev files: **python3.5-config --includes** The output should be similar to: **-I/usr/include/python3.5m** **-I/usr/include/x86_64-linux-gnu/python3.5m**. The first part of the output is the expected location & the second part shows the current location of the config file. To solve this problem, we’ll copy the file from the current location to the expected location:
```shell=
sudo cp /usr/include/x86_64-linux-gnu/python3.5m/pyconfig.h /usr/include/python3.5m/
```
---
5. Create a temporary directory, move into it and run:
```shell=
git clone https://github.com/opencv/opencv.git
```
This will download OpenCV 3. Then rename the folder **opencv** to **opencv-3**
---
6. Create a **build** directory, move to it and run:
```shell=
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../opencv-3
```
After the process is finished, run ``` make ``` and then ```sudo make install```.
Enjoy.