1、确定tensorfolw版本
首先根据nx系统版本安装匹配的tensorflow,参考官方给出的建议:链接
我手上nx系统是JetPack4.5,所以装的1.15
2、安装相关依赖
可以先按照官方给出的依赖包都安装一遍
sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
sudo apt-get install python3-pip
sudo pip3 install -U pip testresources setuptools==49.6.0
sudo pip3 install -U numpy==1.16.1 future==0.18.2 mock==3.0.5 h5py==2.10.0 keras_preprocessing==1.1.1 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11
3、安装tensorflow
因为我想装的tensorflow1.x
sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v45 'tensorflow<2'
假如tensorflow安装不成功,可以尝试参考博文的方法
sudo apt-get install python3-pip
python3 -m pip install --upgrade pip
sudo vim /usr/bin/pip3
输入"i"进入编辑模式
//源文件
from pip import main
if __name__ == '__main__':
sys.exit(main())
//修改后:
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
先按“Esc”,再输入“wq!”保存退出
再把下面依赖都一一装上
sudo apt-get install python3-scipy
sudo apt-get install python3-pandas
sudo apt-get install python3-sklearn
sudo apt-get install libhdf5-serial-dev hdf5-tools
sudo pip3 install Cython -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
sudo pip3 install absl-py==0.7.0
sudo pip3 install gast==0.2.2
sudo pip3 install protobuf==3.11.2
sudo pip3 install wrapt==1.11.2
sudo pip3 install astor==0.8.1
sudo pip3 install google-pasta=0.1.8
sudo pip3 install keras -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v45 'tensorflow<2'
4、测试
nx@nx-desktop:~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-05-20 20:02:20.848291: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
>>> print(tf.__version__)
1.15.5
>>>
5、报错汇总
(1)tensorflow版本不匹配
nx@nx-desktop:~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Illegal instruction (core dumped)
解决方法:JetPack版本与tensorflow版本匹配,一开始我装的是tensorflow_gpu-1.14.0+nv19.10,卸载,重新装tensorflow1.15
sudo pip uninstall tensorflow
(2)缺失模块
No module named 'astor'
No module named 'termcolor'
解决方法:卸载重装
sudo pip3 uninstall astor
sudo pip3 uninstall termcolor
sudo pip install astor
sudo pip install termcolor