2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pyenvをWSL(Ubuntu)にinstallしてPythonのバージョンを切り替える

Last updated at Posted at 2024-04-22

なぜこの記事を書いたのか

githubのリポジトリにやり方が書いてありますが,Macはbrewとかで比較的簡単にinstallできそうだったが,ubuntuを使っている自分はinstallに手間取ったので防備録として書きました。

対象の読者

  • Ubuntuユーザ
  • WSL(Ubuntu)ユーザ

pyenvのインストール方法

sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
curl https://pyenv.run | bash

これにより~/.pyenvにリポジトリがダウンロードされています。

  • ~/.pyenv/binのPATHを通します。
echo 'export PYENV_ROOT="~/.pyenv"' >> ~/.bashrc
export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc

pyenv使い方

今回はpython3.12を使いたかったので3.12をグローバルにして設定する。

pyenv install --list | grep 3.12 # 使用可能なバージョンを探す
pyenv install 3.12.0
pyenv global 3.12.0

参考

自分がDockerfile書いてるので参考までにDockerfile

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?