LoginSignup
5
2

More than 3 years have passed since last update.

Jetson Nanoでpyenv

Last updated at Posted at 2019-06-08

はじめに

Jetson Nanoにインストールされているpython3は3.6.7である。pipenvでディレクトリごとに環境を構築していると、異なるバージョンのPythonを使いたくなることがある。こんなときに使用するのがpyenvである。

pipenvはpyenvと連携するため、pipenv + pyenvの組み合わせでディレクトリごとに異なるPythonバージョンを伴う環境を構築することができる。

パッケージのインストール

aptコマンドを使ってPythonをソースコードからコンパイルする上で必要なパッケージ群をインストールする。

ターミナル
sudo apt install libssl-dev libffi-dev libbz2-dev libncurses5-dev libdb-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev

pyenvのインストール

pyenvはaptやpipではインストールできないのでgitを使ってインストールする。

ターミナル
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

~/.bashrcの最後に下記を追加。

~/.bashrcの最後
# pyenv settings
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

設定の読み込みを行う。

ターミナル
source ~/.bashrc

インストールの確認はpyenv -hで行う。

ターミナル
yamamo-to@jetson-nano:~$ pyenv -h
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

異なるPythonのバージョンをインストール

試しに$HOME/Documents/Python3.5以下に、python 3.5の環境を構築する。

ターミナル
yamamo-to@jetson-nano:~$ mkdir ~/Documents/Python3.5
yamamo-to@jetson-nano:~$ cd ~/Documents/Python3.5
yamamo-to@jetson-nano:~/Documents/Python3.5$ pipenv --python 3.5

「システムにPython 3.5が見つからないのでpyenvを使ってCPythonをインストールして良いか?」のようなメッセージが表示されるので「y」と答える。これでしばらく待つとPython 3.5が利用可能となる。

ターミナル
yamamo-to@jetson-nano:~/Documents/Python3.5$ pipenv run python -V
Python 3.5.7

実行時のイメージは下記の画像の通り。

python3.5.png

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2