xavier nx環境配置流程記錄
- 引言
- 1.板子環境
- 2.設置默認python和pip
- 2.安裝torch和torchvision
- 2.1 下載正確的whl安裝文件
- 2.2 開始安裝
- 2.3 查看torch安裝情況
- 3.問題記錄
- 3.1 問題1:Running pip as the 'root' user can result in broken permissions
- 3.2 問題2:torch不支持GPU
- 3.3 問題3:torch安裝時報錯平臺有問題
- 3.4 安裝進度緩慢
- 3.5 zipimport.ZipImportError: can't decompress data; zlib not available
- 3.6 pip._vendor.urllib3.exceptions.ReadTimeoutError
引言
最近工作需要重新配置板子環境,過程中仍有很多問題,借此機會記錄一下,方便後續參考。
1.板子環境
// 查看jetson版本號
nvidia@nvidia-desktop:~/Downloads/torch&torchvision$ uname -a
Linux nvidia-desktop 4.9.253-tegra #4 SMP PREEMPT Tue Oct 31 01:10:22 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
// 或者通過:
sudo jtop
我的版本是jetpack4.6。
// 查看cuda版本號
nvidia@nvidia-desktop:~/Downloads/torch&torchvision$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Feb_28_22:34:44_PST_2021
Cuda compilation tools, release 10.2, V10.2.300
Build cuda_10.2_r440.TC440_70.29663091_0
2.設置默認python和pip
运行以下命令来更新:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 2
这将将Python 3.6的路径添加到/usr/bin/python的备选项列表中,并分配优先级1。
使用以下命令直接確認默认Python版本:
sudo update-alternatives --config python
直接在終端輸入選擇的默認版本號就行。
更新系统环境配置变量:
sudo gedit ~/.bashrc
// 在最下面添加:
export PATH="/usr/bin/python3.6:$PATH"
// 更新配置:
source ~/.bashrc
設置可選pip:
sudo update-alternatives --install /usr/bin/pip pip /home/nvidia/.local/bin/pip 3
sudo update-alternatives --install /usr/bin/pip pip /home/nvidia/.local/bin/pip3.6 1
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.7 2
// 查看配置:
sudo update-alternatives --list pip
// 選擇默認:
sudo update-alternatives --config pip
直接在終端輸入默認選擇的版本號就行。
2.安裝torch和torchvision
2.1 下載正確的whl安裝文件
由於是arrch64架構,需要從nvidia網址選擇下載文件:
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
链接: link.
在該網站選擇對應CUDA版本和python版本的torch whl文件下載,需要翻牆。
百度網盤我也下載了幾個文件,可以參考:
链接:https://pan.baidu.com/s/1udiGhHqSLFe_Ol3UZdylGQ?pwd=jqvb
链接: link.
提取码:jqvb
裏面有torch和對應的torchvision.
我的CUDA版本10.2,python版本3.6.9,選擇安裝上圖所示文件。
2.2 開始安裝
// 安裝torch
pip install torch-1.8.0-cp36-cp36m-linux_aarch64.whl// 安裝torchvision
unzip vision-v0.9.0.zip
sudo gedit ~/.bashrc
//在最後添加:
"export BUILD_VERSION=0.9.0"
//更新文件配置:
source ~/.bashrc
//編譯
python setup.py install --user
2.3 查看torch安裝情況
nvidia@nvidia-desktop:~$ python
Python 3.6.9 (default, Mar 10 2023, 16:46:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.8.0'
>>> torch.cuda.is_available()
True
3.問題記錄
3.1 問題1:Running pip as the ‘root’ user can result in broken permissions
WARNING: The directory '/home/nvidia/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
// 使用下方命令
sudo chown -R root /home/nvidia/.cache/pip/
sudo chown -R root /home/nvidia/.cache/pip/http/
3.2 問題2:torch不支持GPU
raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
安裝對應cuda和python版本的torch
3.3 問題3:torch安裝時報錯平臺有問題
ERROR: torch-1.7.1-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.
上述whl文件只能在linux上使用,不能在xavier nx 上使用。jetson板子對應的torch下載網址:
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
3.4 安裝進度緩慢
嘗試使用清華源下載安裝
sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyYAML
3.5 zipimport.ZipImportError: can’t decompress data; zlib not available
Traceback (most recent call last):File "/usr/local/bin/pip", line 5, in <module>from pip._internal.cli.main import mainFile "/usr/lib/python3/dist-packages/pip/__init__.py", line 24, in <module>from urllib3.exceptions import DependencyWarning
zipimport.ZipImportError: can't decompress data; zlib not available
下載安裝:
nvidia@nvidia-desktop:~$ sudo apt-get install zlib*
3.6 pip._vendor.urllib3.exceptions.ReadTimeoutError
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
網速太慢,換個源:
pip install opencv-python -i http://pypi.douban.com/simple --trusted-host pypi.douban.com