{"title":"Django のインストール方法","version":"4.2","locale":"ja","docname":"topics/install","url":"/ja/4.2/topics/install/","canonical":"https://djangodocs.dev/ja/4.2/topics/install/","summary":"このドキュメントを読めば、Django をセットアップして、起動することができます。Django は Python のウェブフレームワークです。","html":"<h1>Django のインストール方法<a class=\"heading-anchor\" href=\"#how-to-install-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>このドキュメントを読めば、Django をセットアップして、起動することができます。</p>\n<section id=\"install-python\">\n<h2>Python をインストールする<a class=\"heading-anchor\" href=\"#install-python\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django は Python のウェブフレームワークです。詳しくは <a class=\"reference internal\" href=\"/ja/4.2/faq/install/#faq-python-version-support\"><span class=\"std std-ref\">どのバージョンの Python で Django が使えますか?</span></a> を参照してください。</p>\n<p>最新版のPythonを <a class=\"reference external\" href=\"https://www.python.org/downloads/\">https://www.python.org/downloads/</a> もしくはOSのパッケージ管理ツールで取得してください。</p>\n<aside class=\"admonition-python-on-windows admonition\" role=\"note\">\n<p class=\"admonition-title\">Windows にインストールする</p>\n<p>もし Windows を使っていてこれから Django を始めるなら、 <a class=\"reference internal\" href=\"/ja/4.2/howto/windows/\"><span class=\"doc\">Windows での Django のインストール方法</span></a> を読むとよいでしょう。</p>\n</aside>\n</section>\n<section id=\"install-apache-and-mod-wsgi\">\n<h2>Apache と <code class=\"docutils literal notranslate\">mod_wsgi</code> のインストール<a class=\"heading-anchor\" href=\"#install-apache-and-mod-wsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>もし単に Django を使って実験したいだけなら、このセクションは飛ばしてください。 Django には軽量 web サーバーが含まれており、テスト用にそれが使えます。本番環境にデプロイするときまで、 Apache をセットアップする必要はありません。</p>\n<p>本番サイトで Django を使用する場合は、<a class=\"reference external\" href=\"https://httpd.apache.org/\">Apache</a> と <a class=\"reference external\" href=\"https://modwsgi.readthedocs.io/en/develop/\">mod_wsgi</a> を使用します。mod_wsgi は、埋め込みモードまたはデーモンモードの2つのモードのいずれかで動作します。埋め込みモードでは、mod_wsgi は mod_perl と似ています。つまり Apache に Python を埋め込み、サーバーの起動時に Python コードをメモリにロードします。コードは Apache プロセスの存続期間中、メモリに残ります。これにより、他のサーバー配置よりも大幅にパフォーマンスが向上します。デーモンモードでは、mod_wsgi はリクエストを処理する独立したデーモンプロセスを生成します。デーモンプロセスはウェブサーバーとは異なるユーザーとして実行できるため、セキュリティが向上する可能性があります。デーモンプロセスは、Apache ウェブサーバー全体を再起動せずに再起動できるため、コードベースの更新がよりシームレスになります。mod_wsgi のドキュメントを参照して、セットアップに適したモードを判断してください。mod_wsgi モジュールをアクティブにして Apache がインストールされていることを確認してください。Django は、mod_wsgi をサポートするすべてのバージョンの Apache で動作します。</p>\n<p>インストール完了後の mod_wsgi の設定方法に関する情報については、<a class=\"reference internal\" href=\"/ja/4.2/howto/deployment/wsgi/modwsgi/\"><span class=\"doc\">Django を Apache と mod_swgi とともに使うには？</span></a> を読んでください。</p>\n<p>何らかの理由により mod_wsgi が使えなかったとしても、心配はいりません。Django は他にもさまざまな開発オプションをサポートしています。そのうちの一つは <a class=\"reference internal\" href=\"/ja/4.2/howto/deployment/wsgi/uwsgi/\"><span class=\"doc\">uWSGI</span></a> で、<a class=\"reference external\" href=\"https://nginx.org/\">nginx</a> と非常に上手く連携できます。さらに、Django は WSGI の仕様 (<span class=\"target\" id=\"index-2\"></span><a class=\"pep reference external\" href=\"https://peps.python.org/pep-3333/\"><strong>PEP 3333</strong></a>) を満たしているので、各種のサーバープラットフォーム上で動作することが保証されています。</p>\n</section>\n<section id=\"get-your-database-running\">\n<span id=\"database-installation\"></span><h2>データベースを動かす<a class=\"heading-anchor\" href=\"#get-your-database-running\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>DjangoのデータベースAPI機能を使用する場合は、データベースサーバーが実行されていることを確認する必要があります。Djangoは多くの異なるデータベースサーバーをサポートし、<a class=\"reference external\" href=\"https://www.postgresql.org/\">PostgreSQL</a>、<a class=\"reference external\" href=\"https://mariadb.org/\">MariaDB</a>、<a class=\"reference external\" href=\"https://www.mysql.com/\">MySQL</a>、<a class=\"reference external\" href=\"https://www.oracle.com/\">Oracle</a> および <a class=\"reference external\" href=\"https://www.sqlite.org/\">SQLite</a> で公式にサポートされています。</p>\n<p>もしあなたが開発しているプロジェクトが小規模なものか、あるいは本番環境にデプロイしないプロジェクトなら、通常は SQLite が最もよい選択肢です。というのは、SQLite 用にサーバーを動かす必要がないからです。しかし、SQLite は他のデータベースと色々な点で異なります。そのため、もし何か重要なプロジェクトを作る場合は、本番環境で使うデータベースと同じものを使うことを推奨します。</p>\n<p>公式にサポートされているデータベースの他に、サードパーティ製のバックエンドもあります（これらを使うと、他のデータベースを Django から使えます）。</p>\n<p>バックエンドに加えて、 Python のデータベースバインディングをインストールする必要があります。</p>\n<ul class=\"simple\">\n<li><p>もし PostgreSQL を使うなら、<a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a> または <a class=\"reference external\" href=\"https://www.psycopg.org/\">psycopg2</a> パッケージが必要になります。詳細は <a class=\"reference internal\" href=\"/ja/4.2/ref/databases/#postgresql-notes\"><span class=\"std std-ref\">PostgreSQL notes</span></a> を見てください。</p></li>\n<li><p>MySQL や MariaDB を使うなら、 <code class=\"docutils literal notranslate\">mysqlclient</code> のような <a class=\"reference internal\" href=\"/ja/4.2/ref/databases/#mysql-db-api-drivers\"><span class=\"std std-ref\">DB API ドライバー</span></a> が必要になります。詳細は <a class=\"reference internal\" href=\"/ja/4.2/ref/databases/#mysql-notes\"><span class=\"std std-ref\">MySQL バックエンドのためのメモ</span></a> を見てください。</p></li>\n<li><p>SQLite を使うなら、 <a class=\"reference internal\" href=\"/ja/4.2/ref/databases/#sqlite-notes\"><span class=\"std std-ref\">SQLite backend notes</span></a> を読むと良いでしょう。</p></li>\n<li><p>Oracle を使うなら <a class=\"reference external\" href=\"https://oracle.github.io/python-cx_Oracle/\">cx_Oracle</a> のコピーが必要ですが、 <a class=\"reference internal\" href=\"/ja/4.2/ref/databases/#oracle-notes\"><span class=\"std std-ref\">notes for the Oracle backend</span></a> を読んで、 Oracle と <code class=\"docutils literal notranslate\">cx_Oracle</code> の両方について、 Django がサポートするバージョンを確認してください。</p></li>\n<li><p>もし非公式のサードパーティ製バックエンドを使う場合、その他の動作要件についてはそのドキュメントを確認してください。</p></li>\n</ul>\n<p>もし Django の <code class=\"docutils literal notranslate\">manage.py migrate</code> コマンドを使って自動的にデータベースのテーブルを作る (Django のインストールとプロジェクト作成のあとに) つもりなら、そのデータベースに対して Django が create table, alter table のパーミッションを持つ必要があります。一方、手動でテーブルを作るつもりなら、 Django に対して <code class=\"docutils literal notranslate\">SELECT</code>、<code class=\"docutils literal notranslate\">INSERT</code>、<code class=\"docutils literal notranslate\">UPDATE</code>、<code class=\"docutils literal notranslate\">DELETE</code> のパーミッションを与えます。これらのパーミッションを付与してデータベースユーザを作成したあと、プロジェクトの設定ファイルで詳細を指定することになります。詳細については <a class=\"reference internal\" href=\"/ja/4.2/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\">DATABASES</code></a> を見てください。</p>\n<p>データベースのクエリをテストするために Django の <a class=\"reference internal\" href=\"/ja/4.2/topics/testing/\"><span class=\"doc\">testing framework</span></a> を使う場合、テスト用データベースを作成するためのパーミッションが Django に必要です。</p>\n</section>\n<section id=\"install-the-django-code\">\n<span id=\"install-django-code\"></span><h2>Django コードをインストールする<a class=\"heading-anchor\" href=\"#install-the-django-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>インストール手順は特定ディストリビューションのパッケージ、最新公式リリースのダウンロード、最新の開発バージョンなど、インストール対象によって少し異なります。</p>\n<section id=\"installing-an-official-release-with-pip\">\n<span id=\"installing-official-release\"></span><h3><code class=\"docutils literal notranslate\">pip</code> を使用して公式リリースをインストールする<a class=\"heading-anchor\" href=\"#installing-an-official-release-with-pip\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>これが Django をインストールするおすすめの方法です。</p>\n<ol class=\"arabic\">\n<li><p><a class=\"reference external\" href=\"https://pip.pypa.io/\">pip</a> をインストールします。最も簡単なのは、<a class=\"reference external\" href=\"https://pip.pypa.io/en/latest/installation/\">スタンドアローンの pip インストーラー</a> を使う方法です。もしディストリビューションにすでにインストール済みの <code class=\"docutils literal notranslate\">pip</code> があり、バージョンが古い場合は、pip をアップデートする必要があるかもしれません。古い場合は、インストールが機能しないためわかるはずです。</p></li>\n<li><p><a class=\"reference external\" href=\"https://docs.python.org/3/tutorial/venv.html\" title=\"(in Python v3.14)\"><span class=\"xref std std-doc\">venv</span></a> を一読してください。このツールは隔離された Python 環境を提供します。隔離された環境は、システム全体にパッケージをインストールするより実用的です。また、管理者権限なしでもパッケージをインストールできます。<a class=\"reference internal\" href=\"/ja/4.2/intro/contributing/\"><span class=\"doc\">チュートリアルへの貢献</span></a> は、仮想環境を作成する方法について説明しています。</p></li>\n<li><p>仮想環境を作成してアクティブ化したら、次のコマンドを入力します。</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python -m pip install Django\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -m pip install Django\n</code></pre></div></div></div>\n</li>\n</ol>\n</section>\n<section id=\"installing-a-distribution-specific-package\">\n<span id=\"installing-distribution-package\"></span><h3>特定ディストリビューション向けのパッケージをインストールする<a class=\"heading-anchor\" href=\"#installing-a-distribution-specific-package\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference internal\" href=\"/ja/4.2/misc/distributions/\"><span class=\"doc\">ディストリビューション固有のメモ</span></a> を読み、プラットフォームやディストリビューションが公式の Django パッケージやインストーラーを提供しているかどうか確認してください。ディストリビューションが提供するパッケージは、依存関係や対応アップグレードパスの自動インストールが可能になることが多いですが、Django の最新リリースが含まれていることは稀です。</p>\n</section>\n<section id=\"installing-the-development-version\">\n<span id=\"installing-development-version\"></span><h3>開発バージョンをインストールする<a class=\"heading-anchor\" href=\"#installing-the-development-version\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"admonition-tracking-django-development admonition\" role=\"note\">\n<p class=\"admonition-title\">Django の開発をトラッキングする</p>\n<p>If you decide to use the latest development version of Django,\nyou'll want to pay close attention to <a class=\"reference external\" href=\"https://code.djangoproject.com/timeline\">the development timeline</a>,\nand you'll want to keep an eye on the <a class=\"reference internal\" href=\"/ja/4.2/releases/#development-release-notes\"><span class=\"std std-ref\">release notes for the\nupcoming release</span></a>. This will help you stay\non top of any new features you might want to use, as well as any changes\nyou'll need to make to your code when updating your copy of Django.\n(For stable releases, any necessary changes are documented in the\nrelease notes.)</p>\n</aside>\n<p>If you'd like to be able to update your Django code occasionally with the\nlatest bug fixes and improvements, follow these instructions:</p>\n<ol class=\"arabic\">\n<li><p>Make sure that you have <a class=\"reference external\" href=\"https://git-scm.com/\">Git</a> installed and that you can run its commands\nfrom a shell. (Enter <code class=\"docutils literal notranslate\">git help</code> at a shell prompt to test this.)</p></li>\n<li><p>Check out Django's main development branch like so:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-1-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>git clone https://github.com/django/django.git\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-1-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> git clone https://github.com/django/django.git\n</code></pre></div></div></div>\n<p>This will create a directory <code class=\"docutils literal notranslate\">django</code> in your current directory.</p>\n</li>\n<li><p>Make sure that the Python interpreter can load Django's code. The most\nconvenient way to do this is to use a virtual environment and <a class=\"reference external\" href=\"https://pip.pypa.io/\">pip</a>. The\n<a class=\"reference internal\" href=\"/ja/4.2/intro/contributing/\"><span class=\"doc\">contributing tutorial</span></a> walks through how to\ncreate a virtual environment.</p></li>\n<li><p>After setting up and activating the virtual environment, run the following\ncommand:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-2-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python -m pip install -e django/\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-2-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -m pip install -e django\\\n</code></pre></div></div></div>\n<p>This will make Django's code importable, and will also make the\n<code class=\"docutils literal notranslate\">django-admin</code> utility command available. In other words, you're all\nset!</p>\n</li>\n</ol>\n<p>When you want to update your copy of the Django source code, run the command\n<code class=\"docutils literal notranslate\">git pull</code> from within the <code class=\"docutils literal notranslate\">django</code> directory. When you do this, Git will\ndownload any changes.</p>\n</section>\n</section>","rootId":"how-to-install-django","toc":[{"title":"Python をインストールする","anchor":"install-python","children":[]},{"title":"Apache と mod_wsgi のインストール","anchor":"install-apache-and-mod-wsgi","children":[]},{"title":"データベースを動かす","anchor":"get-your-database-running","children":[]},{"title":"Django コードをインストールする","anchor":"install-the-django-code","children":[{"title":"pip を使用して公式リリースをインストールする","anchor":"installing-an-official-release-with-pip","children":[]},{"title":"特定ディストリビューション向けのパッケージをインストールする","anchor":"installing-a-distribution-specific-package","children":[]},{"title":"開発バージョンをインストールする","anchor":"installing-the-development-version","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Django を使う","url":"/ja/4.2/topics/"}],"prev":{"docname":"topics/index","title":"Django を使う","url":"/ja/4.2/topics/"},"next":{"docname":"topics/db/index","title":"モデルとデータベース","url":"/ja/4.2/topics/db/"},"formats":{"html":"/ja/4.2/topics/install/","markdown":"/ja/4.2/topics/install.md","json":"/ja/4.2/topics/install.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/topics/install.txt","official":"https://docs.djangoproject.com/ja/4.2/topics/install/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}