インストール Installation

Pythonのバージョン Python Version

Python 3の最新バージョンを使うことを推奨します。FlaskはPython 3.5以降、Python 2.7、そしてPyPyをサポートします。 We recommend using the latest version of Python 3. Flask supports Python 3.5 and newer, Python 2.7, and PyPy.

依存対象 Dependencies

以下の配付ツール(distributions)はFlaskをインストールするとき、自動的にインストールされます。 These distributions will be installed automatically when installing Flask.

  • Werkzeugは、アプリケーションとサーバの間のインタフェースにおけるPythonでのインタフェースの標準である、WSGIを実装しています。 `Werkzeug`_ implements WSGI, the standard Python interface between applications and servers.

  • Jinjaは、アプリケーションが提供するページの表示(render)をする、テンプレート言語です。 `Jinja`_ is a template language that renders the pages your application serves.

  • MarkupSafeは、Jinjaと一緒にインストールされます。MarkupSafeはテンプレートを表示(render)するときに挿入(injection)攻撃を回避するために、信用できない入力をエスケープします。 `MarkupSafe`_ comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks.

  • ItsDangerousは、インテグリティを確保するために安全にデータへ署名を施します。これはFlaskのセッションのクッキーを保護するために使用されます。 `ItsDangerous`_ securely signs data to ensure its integrity. This is used to protect Flask's session cookie.

  • Clickは、コマンドラインのアプリケーションを書くフレームワークです。flaskコマンドを提供し、独自に作成した管理コマンドを追加できるようにします。 `Click`_ is a framework for writing command line applications. It provides the ``flask`` command and allows adding custom management commands.

オプションの依存対象 Optional dependencies

以下の配布ツール(distributions)は、自動的にはインストールされません。もしインストールされていたときは、Flaskが見つけ出して使用します。 These distributions will not be installed automatically. Flask will detect and use them if you install them.

  • Blinkerは、合図(Signals)のサポートを提供します。 `Blinker`_ provides support for :ref:`signals`.

  • SimpleJSONは、Pythonのjsonモジュールと互換性のある、高速なJSON実装です。インストールされている場合、JSON操作において優先して使われます。 `SimpleJSON`_ is a fast JSON implementation that is compatible with Python's ``json`` module. It is preferred for JSON operations if it is installed.

  • python-dotenvは、flaskコマンドを実行するときdotenvからの環境変数読み込みサポートを有効にします。 `python-dotenv`_ enables support for :ref:`dotenv` when running ``flask`` commands.

  • Watchdogは、より高速な、より効率的な再読み込み機能(reloader)を開発サーバへ提供します。 `Watchdog`_ provides a faster, more efficient reloader for the development server.

仮想環境(Virtual environments) Virtual environments

開発環境と本番環境のどちらでも、自分のプロジェクトの依存対象を管理するためにvirtual environmentを使用します。 Use a virtual environment to manage the dependencies for your project, both in development and in production.

virtual environmentはどんな問題を解決するのでしょうか?自分のPythonプロジェクトの数が増えるほど、PythonライブラリもしくはPython自身の違うバージョンを使って作業する必要性が増えていきがちです。あるプロジェクト用のより新しいバージョンのライブラリが、他のプロジェクトでの互換性を壊す可能性があります。 What problem does a virtual environment solve? The more Python projects you have, the more likely it is that you need to work with different versions of Python libraries, or even Python itself. Newer versions of libraries for one project can break compatibility in another project.

virtual environmentは、プロジェクトごとに1つ用意する、独立したPythonライブラリのグループです。ひとつのプロジェクト用にインストールされたパッケージは、他のプロジェクトやオペレーティングシステムのパッケージには影響を与えません。 Virtual environments are independent groups of Python libraries, one for each project. Packages installed for one project will not affect other projects or the operating system's packages.

Python 3ではvirtual environmentを作成するvenvモジュールも合わせて提供されています。もし最近のバージョンのPythonを使っている場合、次のセクションで続けてください。 Python 3 comes bundled with the :mod:`venv` module to create virtual environments. If you're using a modern version of Python, you can continue on to the next section.

もしPython 2を使っている場合、virtualenvのインストールを最初に確認してください。 If you're using Python 2, see :ref:`install-install-virtualenv` first.

環境の作成 Create an environment

プロジェクトのフォルダと、その中のvenvフォルダを作成します。 Create a project folder and a :file:`venv` folder within:

$ mkdir myproject
$ cd myproject
$ python3 -m venv venv

Windowsでは: On Windows:

$ py -3 -m venv venv

Python 2を使っているためにvirtualenvのインストールが必要な場合は、以下のコマンドを代わりに使ってください: If you needed to install virtualenv because you are using Python 2, use the following command instead:

$ python2 -m virtualenv venv

Windowsでは: On Windows:

> \Python27\Scripts\virtualenv.exe venv

環境を有効化(Activate the environment) Activate the environment

プロジェクトで作業する前に、対応する環境を有効化(activate)します: Before you work on your project, activate the corresponding environment:

$ . venv/bin/activate

Windowsでは: On Windows:

> venv\Scripts\activate

(virtual environmentを有効化すると)有効化された環境の名前を表示するように、プロンプトが変化します。 Your shell prompt will change to show the name of the activated environment.

Flaskのインストール Install Flask

有効化した(仮想)環境の中で、以下のコマンドを使ってFlaskをインストールします: Within the activated environment, use the following command to install Flask:

$ pip install Flask

この時点でFlaskがインストールされました。クイックスタートをチェックするか、ドキュメントの概要へ進んでください。 Flask is now installed. Check out the :doc:`/quickstart` or go to the :doc:`Documentation Overview </index>`.

最新版での作業(Living on the edge) Living on the edge

もしリリース前の最新のFlaskのコードを使って作業したい場合は、masterブランチのコードでインストールまたはアップデートしてください: If you want to work with the latest Flask code before it's released, install or update the code from the master branch:

$ pip install -U https://github.com/pallets/flask/archive/master.tar.gz

virtualenvのインストール Install virtualenv

もしPython 2を使っている場合、venvモジュールが利用できません。代わりに、virtualenvをインストールします。 If you are using Python 2, the venv module is not available. Instead, install `virtualenv`_.

Linuxでは、virtualenvは(OSの)パッケージマネージャによって提供されます: On Linux, virtualenv is provided by your package manager:

# Debian, Ubuntu
$ sudo apt-get install python-virtualenv

# CentOS, Fedora
$ sudo yum install python-virtualenv

# Arch
$ sudo pacman -S python-virtualenv

Mac OS XまたはWindowsを使っている場合は、get-pip.pyをダウンロードし、それから以下を実行します: If you are on Mac OS X or Windows, download `get-pip.py`_, then:

$ sudo python2 Downloads/get-pip.py
$ sudo python2 -m pip install virtualenv

Windowsでは、administratorとして以下を実行します: On Windows, as an administrator:

> \Python27\python.exe Downloads\get-pip.py
> \Python27\python.exe -m pip install virtualenv

ここまでくれば、前の方にある環境の作成へ戻れます。 Now you can return above and :ref:`install-create-env`.