> For the complete documentation index, see [llms.txt](https://huang-jason.gitbook.io/anaconda/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huang-jason.gitbook.io/anaconda/raspberry.md).

# raspberry

```
$  ssh -X pi@141.52.97.159
```

## step 0 - config

```
$ sudo raspi-config
```

Advanced Options -> Expand filesystem

Change user password

Interfacing Options -> SSH

```
$ sudo reboot
```

## Step 1

```
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update
$ sudo reboot
```

## Step 2

```
$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libgtk2.0-dev libgtk-3-dev libcanberra-gtk*
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install vim
```

## Step 3 - miniconda

```
$ mkdir install
$ cd ~/install

$ wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
$ sudo md5sum Miniconda3-latest-Linux-armv7l.sh
$ sudo /bin/bash Miniconda3-latest-Linux-armv7l.sh

$ vim ~/.bashrc
# add: export PATH="/home/pi/miniconda3/bin:$PATH"

$sudo reboot
```

## Step 4

```
$ conda create --name tlc python=3.4 numpy flask
$ source activate tlc
```

## Step 5 - opencv

```
$ cd ~/install
$ wget -O opencv-3.3.1.zip https://github.com/Itseez/opencv/archive/3.3.1.zip
$ wget -O opencv_contrib-3.3.1.zip https://github.com/Itseez/opencv_contrib/archive/3.3.1.zip 
$ unzip opencv-3.3.1.zip
$ unzip opencv_contrib-3.3.1.zip
```

**you need to take care of your env name!!!**

```
$ cd opencv-3.3.1
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/install/opencv_contrib-3.3.1/modules \
    -D PYTHON_EXECUTABLE=/home/pi/.conda/envs/tlc/bin/python \
    -D PYTHON_LIBRARY=/home/pi/.conda/envs/tlc/lib/python3.4 \
    -D PYTHON_INCLUDE_DIR=/home/pi/.conda/envs/tlc/include/python3.4m \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D BUILD_EXAMPLES=OFF ..
```

## Step 6 - install opencv

```
# change swap

$ sudo vim /etc/dphys-swapfile
# CONF_SWAPSIZE=1024

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
```

```
$ make -j4
```

after 2hr

```
$ sudo make install
$ sudo ldconfig
```

change swap back to 100

```python
# change swap

$ sudo vim /etc/dphys-swapfile
# CONF_SWAPSIZE=100

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
```

## Step 7 - link cv2.so changed to:

```python
$ source activate tlc
$ python -c "import sys; print(next(p for p in sys.path if 'site-packages' in p))"
# /home/pi/.conda/envs/tlc/lib/python3.4/site-packages
```

```python
$ cd /home/pi/install/opencv-3.3.1/build/lib/python3/
$ ls
# see what inside, and I found cv2.cpython-34m.so
```

```python
# link cv2.cpython-34m.so to cv2.so
$ cd /home/pi/.conda/envs/tlc/lib/python3.4/site-packages
$ ln -s /home/pi/install/opencv-3.3.1/build/lib/python3/cv2.cpython-34m.so cv2.so
```

## Step 8 - test

```python
remote pi $ ipython notebook --no-browser --port=8989
```

```python
local $ ssh -N -f -L localhost:8989:localhost:8989 pi@141.52.97.173
```

stop process

```python
local $ lsof -ti:8989 | xargs kill -9
```

## Ref

[https://stackoverflow.com/questions/39371772/how-to-install-anaconda-on-raspberry-pi-3-model-b#39371773](https://www.gitbook.com/book/jasonychuang/anaconda/edit#)

<https://gurus.pyimagesearch.com/lessons/installing-opencv-on-your-raspberry-pi/>
