Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing PyTorch, torchvision, spaCy, torchtext on Jetson Nanon [ARM]
#!/bin/bash
# This script will install pytorch, torchvision, torchtext and spacy on nano.
# If you have any of these installed already on your machine, you can skip those.
# Tailored for virtual environments created with python3 -m venv [name]
if [ -z ${VIRTUAL_ENV+x} ]
then
echo "Not in a virtual environment"
exit 1
fi
PYTHON_PATH="${VIRTUAL_ENV}/bin/python3"
PIP_PATH="${VIRTUAL_ENV}/bin/pip3"
sudo apt-get -y update
sudo apt-get -y upgrade
#Dependencies
sudo apt-get install python3-setuptools
#Installing PyTorch
#For latest PyTorch refer original Nvidia Jetson Nano thread - https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/.
wget https://nvidia.box.com/shared/static/yr6sjswn25z7oankw8zy1roow9cy5ur1.whl -O torch-1.6.0rc2-cp36-cp36m-linux_aarch64.whl
sudo apt-get install libopenblas-base
$PIP_PATH install Cython
$PIP_PATH install numpy torch-1.6.0rc2-cp36-cp36m-linux_aarch64.whl
#Installing torchvision
#For latest torchvision refer original Nvidia Jetson Nano thread - https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/.
sudo apt-get install libjpeg-dev zlib1g-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch v0.7.0-rc2 https://github.com/pytorch/vision torchvision # see below for version of torchvision to download
cd torchvision
sudo $PYTHON_PATH setup.py install
cd ../ # attempting to load torchvision from build dir will result in import error
#Installing spaCy
#Installing dependency sentencepiece
sudo apt-get install cmake build-essential pkg-config libgoogle-perftools-dev
git clone https://github.com/google/sentencepiece.git
cd sentencepiece
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install
sudo ldconfig -v
cd ../python
$PYTHON_PATH setup.py build
sudo $PYTHON_PATH setup.py install
cd ../../
git clone https://github.com/explosion/spaCy
cd spaCy/
export PYTHONPATH=`pwd`
export BLIS_ARCH=generic
$PIP_PATH install -r requirements.txt
sudo $PYTHON_PATH setup.py build_ext --inplace
sudo $PYTHON_PATH setup.py install
$PYTHON_PATH -m spacy download en_core_web_sm
cd ../
#Installing torchtext
git clone https://github.com/pytorch/text torchtext
cd torchtext
git submodule update --init --recursive
$PYTHON_PATH setup.py clean install
cd ../
echo "done installing PyTorch, torchvision, spaCy, torchtext"
@Nolence
Copy link

Nolence commented Aug 23, 2020

Thanks for the script! Very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment