LoginSignup
0
1

More than 5 years have passed since last update.

pythonを仮想空間上で行う方法(MacOS用)

Posted at

この記事は、macOSにて、pythonを仮想空間上で行う方法が書かれています。

事前準備:Homebrewのインストール

初めに、Homebrewを用いて、pyenvとpyenv-virtualenvをインストールする。
ターミナルに次のコマンドを入力する。

$brew install pyenv
$brew install pyenv-virtualenv

仮想環境を扱うためのツールが導入することができた。

次に.bash_profileに以下のコードを追加する。

export PYENV_ROOT=${HOME}/.pyenv
if [ -d "${PYENV_ROOT}" ]; then
    export PATH=${PYENV_ROOT}/bin:$PATH
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
fi

これを読み込む。

$ source ~/.bash_profile

pyenvの中に、好きなPythonのバージョンをインストールする。

$ pyenv install 3.x.y

次に、pyenvの中に存在するPythonのバージョンを指定して、仮想環境を構築する。

$ pyenv virtualenv 3.x.y test

好きなディレクトリ上に、test環境を指定する。

$ pyenv local test

これで、そのディレクトリに移動する自動的にtest環境で指定したPythonが実行できる。

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