LoginSignup
37
38

More than 5 years have passed since last update.

MacOSX Mavericks(10.9)にhomebrewを使ってDjangoの開発環境を整える

Posted at

ImportErrorに悩まされた

homebrewでpythonをインストールして、pipでdjangoのインストール。でも、サーバ起動で失敗する。

$ python manage.py runserver

ImportError: No module named django.core.management

実はMacにはPythonが初めから入っている

Terminalアプリを起動しバージョンを確かめてみる

$ python --version

Python 2.7.5

これに気がつかず、てっきりhomebrewでインストールされたPythonかと思ったら違った。

$ which python

/usr/bin/python

Mavericksに入っているPythonが最新版で気がつかなかった...

homebrewのインストール

Xcode 5.0から、Command Line Toolsのインストール方法がかわったようなので、以下のコマンドでインストールする

$ xcode-select --install

homebrewのインストール

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

最後に、以下のコマンドで正常に完了したかの確認

$ brew doctor

Your system is ready to brew.

と出たら完了

Pythonのインストール

Pythonはbrewコマンドで入れることで、pip (Pythonのパッケージ管理)も一緒に入れてくれる

$ brew install python

pipは最新化しておく

$ pip install --upgrade setuptools$ pip install --upgrade pip

homebrewとpythonの環境pathを設定する

echo 'export PATH=/usr/local/bin:/usr/local/share/python:$PATH' >> ~/.bash_profile
source ~/.bash_profile

確認する

$ python --version

Python 2.7.5

$ which python

/usr/local/bin/python

Djangoのインストールとプロジェクトの作成

$ pip install django

プロジェクトの作成を行う

django-admin.py startproject sample_project

これで、カレントディレクトリにsample_projectというディレクトリが作成されるので動かしてみる

cd sample_project
python manage.py runserver

http://127.0.0.1:8000/にアクセスし、以下の画面が表示されれば環境構築完了

It worked!

37
38
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
37
38