Tips:
最初环境为TX2刷机后环境。此时Python为Python 2.7.11+
YOLO2适用于Python3 + OpenCV3。配置时需注意。
一、设置Python默认版本 - Python2与Python3切换
1、此时python环境为2.7.11+
python
Python 2.7.11+(default,Apr 17 2016,14:00:29)
2、进入/usr/bin,并执行两条命令
cd /usr/bin
user@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in auto mode
user@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
3、再次查看已经变成3.5了
user@ubuntu:/usr/bin$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
4、怎么随意切换
user@ubuntu:/usr/bin$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3 150 auto mode
1 /usr/bin/python2 100 manual mode
2 /usr/bin/python3 150 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode
#数字前面有*号表示是当前使用版本,输入1切换到2.7,再次查看如下
user@ubuntu:/usr/bin$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3 150 auto mode
* 1 /usr/bin/python2 100 manual mode
2 /usr/bin/python3 150 manual mode
Press <enter> to keep the current choice[*], or type selection number:
二、配置相关库文件(python3)
1、安装pip/numpy/scipy/matplotlib等
# 安装python3-dev,安装这个包,以后安装各种python扩展包,可以省很多事情
sudo apt-get install python3-dev
# 使用apt-get安装
sudo apt-get install python3-pip
sudo apt-get install python3-numpy
sudo apt-get install python3-scipy
sudo apt-get install python3-matplotlib
2、安装cython/h5py等(YOLO2需要)
sudo pip3 install cython
sudo apt-get install libhdf5-dev
sudo pip3 install h5py
3、cffi库的安装
# 1// 能简单粗暴的安装最好
sudo apt-get install cffi
# 2// 如果不行呢 反正QFF可以这样装
sudo apt-get install python3-dev libffi-dev
sudo pip3 install cffi
三、配置OpenCv3.3.1 with python 3.5
1、安装各种依赖库
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
2、cmake配置编译
# 建立一个build文件夹
cd ~/opencv
mkdir build
cd build
# 编译配置opencv
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D PYTHON_INCLUDE_DIR=/usr/include/python3.5 -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D PYTHON_EXECUTABLE=/usr/lib/python3 -D BUILD_EXAMPLES=ON ..
# ok之后
make -j7
sudo make install
3、Install procedure for pyTorch on NVIDIA Jetson TX1/TX2
#!/bin/bash
#
# pyTorch install script for NVIDIA Jetson TX1/TX2,
# from a fresh flashing of JetPack 2.3.1 / JetPack 3.0 / JetPack 3.1
#
# for the full source, see jetson-reinforcement repo:
# https://github.com/dusty-nv/jetson-reinforcement/blob/master/CMakePreBuild.sh
#
# note: pyTorch documentation calls for use of Anaconda,
# however Anaconda isn't available for aarch64.
# Instead, we install directly from source using setup.py
sudo apt-get install python-pip
# upgrade pip
pip install -U pip
pip --version
# pip 9.0.1 from /home/ubuntu/.local/lib/python2.7/site-packages (python 2.7)
# clone pyTorch repo
git clone http://github.com/pytorch/pytorch
cd pytorch
git submodule update --init
# install prereqs
sudo pip install -U setuptools
sudo pip install -r requirements.txt
# Develop Mode:
python setup.py build_deps
sudo python setup.py develop
# Install Mode: (substitute for Develop Mode commands)
#sudo python setup.py install
# Verify CUDA (from python interactive terminal)
# import torch
# print(torch.__version__)
# print(torch.cuda.is_available())
# a = torch.cuda.FloatTensor(2)
# print(a)
# b = torch.randn(2).cuda()
# print(b)
# c = a + b
# print(c)
网友评论