LoginSignup
14
14

More than 5 years have passed since last update.

macOSにPython3及びPython仮想環境virtualenvを導入

Last updated at Posted at 2018-09-15

はじめに

持っているMacにPython及びPython仮想環境のvirtualenvを導入してみた。

手順

最新のpythonをインストール

$ brew install python

brew自体がMacに導入されていない場合、これを参考に導入してください。
https://qiita.com/balius_1064/items/ac7dff5ef10eaf69996f

インストール完了後に、正しくできたかどうかを確認する。

$ python3 --version
Python 3.7.0

virtualenvをインストール

virtualenvのいいところは、python自体のバージョンまで環境ごとに指定できること。

pip3 install virtualenv

正しくインストールできたかどうかを確認する

$ virtualenv --version
16.0.0

インストールは一応これでOK。次は、仮想環境を作ってみる。

仮想環境を作る

homeディレクトリのhellopyに仮想環境を作る。

$ cd ~
$ mkdir hellopy
$ virtualenv hellopy
Using base prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/yangbin/hellopy/bin/python3.7
Also creating executable in /Users/yangbin/hellopy/bin/python
Installing setuptools, pip, wheel...done.

仮想環境を有効化する

仮想環境を作るだけでまだ使えない。仮想環境を使う時にまず有効化させる必要がある。

$ cd hellopy
$ source bin/activate

これで有効になります。有効になると、コマンドラインのプロンプトに環境が表示されるようになる。

(hellopy) $

仮想環境を無効化する

個人的には、新しいターミナルを開くが、あえて現在のターミナルで仮想環境を無効化するなら、下記のコマンドで。

(hellopy) $ deactivate
14
14
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
14
14