Macプリインストールの確認
$ python --version
Python 2.7.10
$ which python
/usr/bin/python
HomebrewでPython3をインストール
Homebrewでインストールすると、python3.xをpython3
コマンドにシンボリックリンクしたり、後述のpip
コマンドのシンボリックリンクをしてくれるようなので、便利。
- XCodeはインストール済み
- homebrewはインストール済み
インストールバージョン確認
$ brew search python
app-engine-python boost-python@1.59 micropython python-markdown wxpython
boost-python gst-python python python3 zpython
caskroom/cask/kk7ds-python-runtime caskroom/cask/mysql-connector-python
インストール
brew install python3
PATH設定
~/.bash_profile
export PATH=/usr/local/bin:$PATH
$ source ~/.bash_profile
$ python -V
Python 2.7.10
$ python3 -V
Python 3.6.1
pipのインストール
Pythonのパッケージマネージャ。python3インストール時に一緒についてくるとのこと。
$ pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (32.2.0)
wheel (0.29.0)
pip.conf
を置いて、フォーマット指定してね、warningされたので対応。
Macは$HOME/Library/Application Support/pip/pip.conf
にあるらしいが、なかったので作成。
$ cd /Users/kumanoshuta/Library/"Application Support"
$ mkdir pip
$ cd pip
$ vi pip.conf
[list]
format=columns
$ pip3 list
Package Version
---------- -------
pip 9.0.1
setuptools 32.2.0
wheel 0.29.0
pyenvのインストール
python本体のバージョンや利用パッケージを切り替えるための仮想環境を提供してくれる。
バージョン切替が必要なのか、dockerやvergrantでいいのでは、など疑問なので割愛。
Djangoのインストール
$ pip3 install django
Collecting django
Downloading Django-1.11.2-py2.py3-none-any.whl (6.9MB)
100% |████████████████████████████████| 7.0MB 207kB/s
Collecting pytz (from django)
Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
100% |████████████████████████████████| 491kB 1.7MB/s
Installing collected packages: pytz, django
Successfully installed django-1.11.2 pytz-2017.2
$ pip3 list
Package Version
---------- -------
Django 1.11.2
pip 9.0.1
pytz 2017.2
setuptools 32.2.0
wheel 0.29.0
Djangoアプリを生成、起動
$ django-admin startproject mysite
$ python3 manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 13, 2017 - 04:16:41
Django version 1.11.2, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
なんかエラーがでてるが、起動はできた。
次はDB設定をする