Jetson Nano - 開發環境
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Python 3
Jetson Nano 已內建安裝 Python 2 與 Python 3, 但預設執行的版本為 Python 2。
將 Python 3 為預設的 Python 環境
直接在 .bashrc 設一個 Python 別名為 Python 3 來啟動
- 修改 .bashrc
$ sudo nano ~/.bashrc
- 在文檔的最下面加上
alias python=python3
- Ctrl+O 存檔 => Enter => Ctrl+X 離開
- 要記得, 讓環境變數即刻生效
$ source ~/.bashrc
輸入 python 後, 應該就可發現已是 3.x.x 版本了
$ python 然後輸入 exit() 離開
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 下載與安裝 python3-pip
$ sudo apt-get install python3-pip
- 升級至最新版本
$ python -m pip install --upgrade pip
- 查詢目前 pip3 版本
$ pip3 -V
- 後續要安裝其他套件在 Python 3 環境下時
$ pip3 install 套件名稱
Python 虛擬環境
建議使用 mkvirtualenv 來建構虛擬環境,相較於 virtualenv 易於管理。此外,進入虛擬環境使用 workon 指令可更簡單方便的切換至指定開發環境
安裝 virtualenv 與 virtualenvwrapper
- 下載與安裝
$ sudo pip3 install virtualenv virtualenvwrapper
- 修改執行環境設定
$ nano ~/.bashrc
- 在文檔的最後加入下列文字
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Ctrl+O 存檔 => Enter => Ctrl+X 離開
- 要記得, 讓環境變數即刻生效
$ source ~/.bashrc
為新專案建立一個虛擬環境
例如專案名為 aicar, 解譯器是 python3
- 新增虛擬環境
$ mkvirtualenv aicar -p python3 --system-site-packages
- 查詢目前已建立虛擬環境的專案名
$ workon
- 進入專案 aicar 的虛擬環境
$ workon aicar
$ pip3 list
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 離開專案 aicar 的虛擬環境
$ deactivate
$ pip3 list
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
有無發現 list 出來的底層環境與虛擬環境中所安裝的套件有何差別?
- 若要刪除虛擬環境
$ rmvirtualenv 專案名
Python 專案套件
OpenCV
Jetson Nano 時就預設已安裝 4.1.1 版本
-
檢查目前已安裝的 OpenCV 版本
$ opencv_version
或從 Python 中檢查版本
$ python3
由上均可得知, OpenCV 已安裝, 且目前版本為 4.1.1
-
查 OpenCV 的安裝載入位置
$ sudo find / -name "cv2*"
-
檢查目前已安裝的 CUDA 版本 (在初始燒錄 Jetson Nano 時就預設已安裝)
$ nvcc -V
一開始若直接執行 nvcc -V 是不會成功的,因為在環境變數中尚未設定 CUDA 的路徑。所以, 須直接指名路徑來執行
$ /usr/local/cuda/bin/nvcc -V
得知我的 Jetson Nano 預設已裝的是 release 10.2, V10.2.89
-
將路徑加入環境變數中
$ ls -al /usr/local
可以得知目前的 cuda 所鏈結的目錄是 cuda-10.2
$ sudo nano ~/.bashrc
在最後面加入以下內容:
編輯完成後,存檔離開, 下指令使其即刻生效
$ source ~/.bashrc
再下指令測試, 可發現已可取得版本資訊, 代表路徑變數設定已成功
$ nvcc -V
安装 PyCuda
$ pip3 install 'pycuda>=2019.1.1'
- 檢查目前已安裝的 cuDNN 版本 (在初始燒錄 Jetson Nano 時就預設已安裝)
$ ls -al /usr/src
可以看到檔案列表中有一個範例程式的目錄 (我的是 cudnn_sample_v8)
$ cd /usr/src/cudnn_samples_v8/mnistCUDNN
$ sudo make
$ sudo chmod a+x mnistCUDNN
$ ./mnistCUDNN
執行後, 接著會看到一些運算的過程, 直到最後一句是 "Test passed!" 表示內建的 cuDNN 是運作正常的。
for python 3.6 版本:
$ wget https://nvidia.box.com/shared/static/9eptse6jyly1ggt9axbja2yrmj6pbarc.whl -O torch-1.6.0-cp36-cp36m-linux_aarch64.whl
$ sudo apt-get install libopenblas-base libopenmpi-dev
$ pip3 install Cython
$ pip3 install numpy torch-1.6.0-cp36-cp36m-linux_aarch64.whl
- 檢查目前已安裝的 TensorRT 版本 (在初始燒錄 Jetson Nano 時就預設已安裝)
$ dpkg -l | grep TensorRT
可得知 TensorRT 版本為 7.1.3
- 先檢查一下, 目前 JetPack 的版本
$ jetson_release
我的是 JetPack 4.4 [L4T 32.4.3]
- 在安裝 TensorFlow 前, 須先裝裝一些前置套件
$ sudo apt-get update
$ sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
- 更新 pip3
$ sudo apt-get install python3-pip
$ sudo pip3 install -U pip testresources setuptools
- 安裝一些相關的套件
$ sudo pip3 install -U numpy1.16.1 future0.18.2 mock3.0.5 h5py2.10.0 keras_preprocessing1.1.1 keras_applications1.0.8 gast==0.2.2 futures protobuf pybind11
- 安裝最新版的 TensorFlow, 相容於 JetPack 4.4
$ sudo pip3 install –pre –extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 tensorflow
- 檢查目前已安裝的 TensorFlow 版本
$ python3
若無錯誤訊息出現, 表示已安裝成功
若要解除安裝 TensorFlow 相當容易, 只須下指令如下:
$ sudo pip3 uninstall -y tensorflow
- 既然裝了 TensorFlow,那就把 Keras 也安装上,它能讓 TensorFlow使用上變得更簡單些
$ pip3 install keras
- 檢查目前已安裝的 Keras 版本
$ python3
若無錯誤訊息出現, 出現剛剛 Tensorflow 一樣的訊息
$ pip3 install yolo34py-gpu
參考 https://www.jianshu.com/p/f98a69b94deb
讓我們能透過 Python 操控 Jetson Nano 上的 40組 GPIO 接腳。
- 安裝 GPIO 函式庫 (預設已安裝)
$ sudo pip install Jetson.GPIO
$ sudo pip3 install Jetson.GPIO
- 給予權限
$ sudo groupadd -f -r gpio
$ sudo usermod -a -G gpio 你的帳號
- 測試是否已安裝可被引用
$ python3

$ sudo -H pip3 install -U jetson-stats
sudo systemctl restart jetson_stats.service
$ sudo reboot
🚀 That's it! 🚀
記得還要重開機後, jetson-stats 的相關工具集就會被啟用
Jtop 監控工具
可用來查看系統運作時 CPU、GPU、記憶體各硬體的情況
$ jtop
按 q 離開監控畫面

程式中可直接使用 jetson-stats 所提供的函式庫的範例說明
jetson_config
Check jetson-stats health, enable/disable desktop, enable/disable jetson_clocks, improve the performance of your wifi
$ jetson_config

jetson_release
顯示 NVIDIA Jetson 的狀態與所有資訊
$ jetson_release

jetson_swap
管理 Jetson Nano 上的 swapfile
$ sudo jetson_swap
$ export | grep JETSON

開發者 IDE 工具
pyCharm
從開發者本機上存取遠端 Jetson Nano 主機上的程式碼
- Tools -> Deployment -> Configuration
- 點選左上角 “+”,添加 SFTP 連線,server name 可設置為 Jetson-Nano
- Connection 中的一些參數設定:
- Host: 填 Jetson-nano 的 IP
- User name: 填 Jetson-nano 的登入用戶帳號
- PassWord: 填 Jetson-nano 的登入用戶密碼 (勾選記住密碼)
- Root path: 可以不用自己填,直接點選旁邊的 Autodetect 即可
- 完成後,點選旁邊的 Mappings
- Mappings: 設定文件對應關係
- Local path: 本地文件路徑
- Deployment path: Jetson nano 上的文件路徑
- 到此為止,SFTP 連線設定大致已完成,可以點擊 Tools -> Deployment -> Brose Remote Host, 即可在 pyCharm的右側視窗看見 Jetson-nano 中的文件了。
注意,修改完程式碼後,還需要點擊右上方的 upload 箭頭符號,程式碼才會同步部屬至 Jetson-nano。
經過以上設定後,程式開發者就可以在本機的 pyCharm 上撰寫 Jetson-nano 上面的程式碼。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Jetson Nano 的 CPU 是 ARM 64位元, 作業系統為 Ubuntu 18.04 的 .deb 檔
- 指定為最新版本
VERSION=latest
- 或指定版本 (例如 1.51.1)
VERSION=1.51.1
- 下載
wget -N -O vscode-linux-deb.arm64.deb https://update.code.visualstudio.com/$VERSION/linux-deb-arm64/stable
- 安裝
sudo apt install ./vscode-linux-deb.arm64.deb
- 安裝 Python linter
$ pip3 install pylint
- 安裝 Python formatter
$ pip3 install black
- 安裝 Python extension for Visual Studio Code
$ code --install-extension ms-python.python --force
- 進入圖形化作業系統 (本地 or 遠端桌面連線)
- 由應用系統選單中啟動
- 或由終端機下指令啟動
$ code
