35
30

More than 5 years have passed since last update.

RaspberryPiにpyenvでPython3環境を作る

Posted at

RaspberryPiにpyenvを導入を参考にして python3系をpyenv下でインストールする

pyenvに必要なパッケージのインストール

$ sudo apt-get install -y git openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev

pyenvのインストール

$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv

クローンし終わったら.bash_profileに設定を追加する。

emacs信者の人は先に $ sudo apt-get install emacs24 してemacsを入れておきましょう

$ sudo emacs ~/.bash_profile

# 以下の内容を追記
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

ちなみに、「.bash_profile.bashrcではなく?」という人はこちらのリンク参照

インストールできるバージョンの一覧表示

$ pyenv install --list

今回は適当に3.5.1あたりをインストール(けっこう時間かかると思うので☕でも淹れて待ちましょう)

$ pyenv install 3.5.1

もしもパッケージ無いよ的なエラーや警告が発生したら無いと言われたものをinstallする

現状のpythonのバージョンを確認

$ python --version
Python 2.7.5

インストールした python3系に切り替え

$ pyenv global 3.6.1

もう一度 python -Vすると切り替わっていることわかる

pi@raspberrypi:~ $ python -V
Python 3.6.1

元のsystemのpythonに戻したくなったら

$ pyenv global system
35
30
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
35
30