Skip to content

Using virtualenv to install python packages on SD card

Yihui Xiong edited this page Sep 1, 2016 · 1 revision

ReSpeaker has very limited on-board flash storage (about 5M) left for users. As most of our main development language is python, we'd better install python packages on SD card.

  1. Create an EXT4 format partition. For example, format a SD card into two partitions, one is FAT32, the other is EXT4:
fdisk /dev/mmcblk0
# ------------------ fdisk ------------------------
>Command (m for help):o
>Created a new DOS disklabel
>Command (m for help):n
>Partition type
 p   primary (0 primary, 0 extended, 4 free)
 e   extended (container for logical partitions)
>Select (default p):p
>Partition number (1-4, default 1):1
>First sector (2048-31116287, default 2048):
>Last sector, +sectors or +size{K,M,G,T,P} (2048-xxxx, default xxxx): +2G
>Command (m for help):n
>Partition type
 p   primary (0 primary, 0 extended, 4 free)
 e   extended (container for logical partitions)
>Select (default p):p
>Partition number (1-4, default 2):2
>First sector (2048-31116287, default 2048):
>Last sector, +sectors or +size{K,M,G,T,P} (2048-xxxx, default xxxx): +2G
>Command (m for help):w
# ------------------ end ------------------------

mkfs.fat /dev/mmcblk0p1
mkfs.ext4 /dev/mmcblk0p2

# reload mtk_sd kernel module
rmmod mtk_sd
insmod mtk_sd
  1. Download virtualenv template

cd /Media/SD-P2 && git clone https://github.com/respeaker/respeaker_virtualenv env

  1. Activate python virtual environment
. /Media/SD-SP2/env/bin/activate

The shell prompt will change from root@xxx:xxx# to (env) root@xxx:xxx#

  1. Install python packages on SD card. For example, install ReSpeaker Python Library and pyusb
pip install --no-cache-dir https://github.com/respeaker/respeaker_python_library/archive/master.zip
pip install --no-cache-dir https://github.com/respeaker/pyusb/archive/master.zip
  1. Run your python script. If you setup a new console or ssh terminal, do step 3 to activate python virtual environment