Windows での Django のインストール方法¶
This document will guide you through installing Python 3.5 and Django on Windows. It also provides instructions for installing virtualenv and virtualenvwrapper, which make it easier to work on Python projects. This is meant as a beginner’s guide for users working on Django projects and does not reflect how Django should be installed when developing patches for Django itself.
The steps in this guide have been tested with Windows 7, 8, and 10. In other versions, the steps would be similar. You will need to be familiar with using the Windows command prompt.
Python をインストールする¶
Django は Python のウェブフレームワークなので、コンピュータには Python がインストールしておく必要があります。この記事を書いている時点では、Python 3.5 が最新版です。
To install Python on your machine go to https://python.org/downloads/. The
website should offer you a download button for the latest Python version.
Download the executable installer and run it. Check the box next to Add
Python 3.5 to PATH
and then click Install Now
.
インストール後、コマンドプロンプトを開き、次のコマンドを実行して、Python のバージョンが今インストールしたバージョンと一致するかどうか確認します。
python --version
About pip
¶
pip は Python のパッケージマネージャです。pip を使えば、Python のパッケージ (たとえば Django のような!) のインストールやアンインストールが非常に簡単に行えます。インストールのセクションでは、これ以降コマンドラインから pip
を使って Python のパッケージをインストールします。
To install pip on your machine, go to
https://pip.pypa.io/en/latest/installing/, and follow the Installing with
get-pip.py
instructions.
virtualenv
と virtualenvwrapper
のインストール¶
virtualenv と virtualenvwrapper は、作成した Django プロジェクトごとに専用の環境を用意してくれるパッケージです。プロジェクト用の環境を作るのは必須ではありませんが、ベストプラクティスだと考えられていて、将来自分のプロジェクトをデプロイしようとするときに無駄な時間を費やすのを防いでくれます。まずは、次のコマンドを実行しましょう。
pip install virtualenvwrapper-win
そして、次のコマンドでプロジェクト用の仮想環境を作成します。
mkvirtualenv myproject
仮想環境は自動的に有効 (activate) にされ、コマンドプロンプトの隣に、仮想環境内にいることを示す “(myproject)” という文字列が表示されるはずです。新しいコマンドプロンプトを始めるには、次のコマンドを用いて、もう一度環境を有効にする必要があります。
workon myproject
Django をインストールする¶
Django can be installed easily using pip
within your virtual environment.
In the command prompt, ensure your virtual environment is active, and execute the following command:
pip install django
これにより、Django の最新版のリリースがダウンロードされ、インストールされます。
インストールが完了したら、コマンドプロンプトで django-admin --version
というコマンドを実行することで、Django が正しくインストールされたかどうかを確認することができます。
Django とともにデータベースをインストールするための情報については、 Get your database running を参照してください。
よくある落とし穴¶
どんな引数を与えても
django-admin
がヘルプテキストしか表示してくれない場合、Windows のファイルの関連付けに問題がある可能性があります。PATH
に Python のスクリプトを実行するのに必要な環境変数が2つ以上設定されていないかどうか確認してください。2つ以上のバージョンの Python をインストールした時にこの問題が起こることがあります。プロキシ経由でインターネットに接続している場合、
pip install django
というコマンドを実行する時にエラーが表示される場合があります。その場合には、コマンドプロンプトに次のコマンドを入力して、プロキシの設定用の環境変数を設定してください。set http_proxy=http://username:password@proxyserver:proxyport set https_proxy=https://username:password@proxyserver:proxyport