Install Python3.7 on Jetson TK1 From Source
In the previous story, we are successfully installing Python3.6 on Jetson TK1 from source, now we will try to install Python3.7 from source in same device. The background come with several latest module version in python, required Python 3.7 or above (at least when this article created).
General Information
- OS : Ubuntu 14.04
- Architecture : Armv7 (ARM 32bit)
Before Started
- Ensure to remove Python 3.7 if previously installed through
apt
or via PPA,
sudo apt-get autoremove python3.7
Download, Configure & Compile Python3.7
- Install prerequisite module,
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev libbz2-dev libc6-dev
sudo apt-get install libgdbm-dev libncursesw5-dev
sudo apt-get install libreadline-gplv2-dev
- Build OpenSSL ver 1.1.1 by refer to this story,
- Download Python 3.7 source,
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
tar xvf Python-3.7.1.tar.xz
cd Python-3.7.1
- Configure and Install Python 3.7,
./configure --enable-shared --enable-optimizations --with-ensurepip=yes CFLAGS="-I$HOME/openssl/include" LDFLAGS="-L$HOME/openssl/lib"sudo make altinstall
- add
/usr/lib
toLD_LIBRARY_PATH
system variables in~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib/' >> ~/.bashrc
- reload
~/.bashrc
,
source ~/.bashrc
- After installation complete, check
ssl
module, (nothing outputs, it’s ok),
python3.7 -m ssl
- Verify installation by checking installed pip version,
pip3.7 -V
- Output should be,
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
Check If Python Dev Included
- Python Dev contain header files that can be used for building Python extension, to check our installation successfully included a Python Dev into it, use script below,
from distutils.sysconfig import get_makefile_filename as m
from os.path import isfile
import sys
sys.exit(not isfile(m()))
- Save as
check-py-dev.py
, - Then run this command in terminal,
python3.7 check-py-dev.py && echo "Ok" || echo "Error: Python header files NOT found"
- The output should be
"ok”
.
Creating Virtual Environment
- After Python 3.7 installation success, now we can create Virtual Environment,
mkdir -p ~/Python3.7/env
python3.7 -m venv ~/Python3.7/env
- Activate Environment,
source ~/Python3.7/env/bin/activate
- After that, your environment will be active in current terminal session,
(env) ubuntu@tegra-ubuntu:~/
Install Python Module
- Upgrade pip from
pip-10.0.1
topip-21.2.3
(latest version when this article created),setuptools
&wheel
,
python3.7 -m pip install --upgrade pip setuptools wheel
- Install
numpy-1.21.1
(latest version when this article created),
python3.7 -m pip install numpy
- Install
matplotlib-3.4.2
(latest version when this article created),
python3.7 -m pip install matplotlib
Note
After finish installing
numpy
andmatplotlib
, we will install other module by building it from from source.The reason behind I choose this way, because I can’t install
scipy
throughpip
due to error during compilation.Besides that I also tried to install
scipy
usingpip wheel
, installation success, but it gives me error when importingscipy.sparse
due to old version oflibstdc++.so.6
which doesn’t supportCXXABI_1.3.9
.
- So, for the next part, we will try building
scipy-1.3.3
from source (compiling version1.7.1
,1.6.1
,1.5.1
ad1.4.1
gives me error). - Install necessary module for building from source,
python3.7 -m pip install pybind11
python3.7 -m pip install pythran
- Install dependencies library (BLAS),
sudo apt-get install libblas-dev liblapack-dev gfortran
- Build & Install
scipy-1.3.3
from source,
wget https://github.com/scipy/scipy/releases/download/v1.3.3/scipy-1.3.3.tar.gz tar -xzvf scipy-1.3.3.tar.gz scipy-1.3.3
cd scipy-1.3.3/ python3.7 setup.py install
- Install
scikit-image-0.18.2
(latest version when this article created),
python3.7 -m pip install scikit-image
- Install
pandas-1.2.5
,
python3.7 -m pip install pandas==1.2.5
- Install
scikit-learn-0.22.2
(compilation takes all night),
python3.7 -m pip install scikit-learn
python3.7 -m pip install pickle-mixin
- Test installed module, save below script into
svm-iris.py
, then run using pyhton3.7,
- The result should look like this,
If you are interest to Web Development
- Install Flask & necessary module,
python3.7 -m pip install Flask
python3.7 -m pip install Flask-Admin
python3.7 -m pip install Flask-SQLAlchemy
python3.7 -m pip install Flask-Security
python3.7 -m pip install enum34
python3.7 -m pip install python-socketio
python3.7 -m pip install flask-socketio
python3.7 -m pip install flask_sqlalchemy
python3.7 -m pip install flask_wtf
python3.7 -m pip install wtforms wtforms[email]
- Install Coroutine module,
python3.7 -m pip install greenlet eventlet gevent
python3.7 -m pip install gevent-websocket
Installing Library in User Space
- If you want to install a python library in user space by specifying
--user
inpip install
command, don’t forget to add environment variable for that user space directory, - Open
~/.bashrc
and add the following line at the end of configuration,
export PATH=/home/ubuntu/.local/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ubuntu/.local/lib
Source :
- https://github.com/actions/setup-python/issues/93
- https://techglimpse.com/install-python-openssl-support-tutorial
- https://bugs.python.org/issue34028
- https://stackoverflow.com/questions/49875588/importerror-lib64-libstdc-so-6-version-cxxabi-1-3-9-not-found
- https://forums.developer.nvidia.com/t/install-scikit-image/122912/11
- https://yunusmuhammad007.medium.com/install-python3-6-in-jetson-tk1-from-source-524256dbf36f