LoginSignup
0
0

More than 1 year has passed since last update.

ubuntu20.04環境でのpyenvとpipenv

Last updated at Posted at 2021-06-03

目的

ubuntu20.04において、pyenvとpipenvを使ってpythonの仮想環境を構築する

環境

Ubuntu20.04

手順

pyenvをinstallするshellscriptを準備

install-pyenv.sh
function setup-pyenv() {
  sudo apt update
  sudo apt install -y \
  build-essential \
  libffi-dev \
  libssl-dev \
  zlib1g-dev \
  liblzma-dev \
  libbz2-dev \
  libreadline-dev \
  libsqlite3-dev \
  git

  ls ~/.pyenv ||\
  git clone https://github.com/pyenv/pyenv.git ~/.pyenv

  grep '# pyenv init' ~/.bashrc ||\
  cat <<'EOF' >>~/.bashrc
# pyenv init
# ref: https://github.com/pyenv/pyenv
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init --path)"
EOF

}

# Main Function
function main() {
  setup-pyenv
}

main

pyenvをinstallする

bash
$ ./install-pyenv.sh

ワークフロー

bash
### pyenvで使いたいpythonのversionをinstallする
$ pyenv install --list
$ pyenv install 3.x.x

### directoryを作成する
$ mkdir myproject && cd pyproject

### pyenvで使いたいpythonのversionを指定し切り替える
$ pyenv local 3.x.x

### 切り替えたpythonのversionでpipを使ってpipenvをinstallする
$ pip install --upgrade pip setuptools
$ pip install pipenv

### pipenvの仮想環境に入る
$ pipenv shell

### pipenv環境から抜けるときはexit
$ exit

### 2回目以降は、そのdirectoryに行って、以下を実行する
$ pipenv shell

Ref

ご教示ありがとうございます。

0
0
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
0
0