windows10にPythonをインストールしてDjangoを動かすまで

# MinicondaでPythonをインストール
- [Miniconda &mdash; Conda   documentation](https://docs.conda.io/en/latest/miniconda.html)
 - インストール先を`C:\Miniconda3`に変更
 - まあ別にどこでもいいけどパスは短いほうが楽だと思った
 - それ以外はデフォルト

## 環境変数を設定
- システム環境変数に追加
 - ```C:\Miniconda3```
 - ```C:\Miniconda3\Scripts```
 - ```C:\Miniconda3\Library\bin```

```bash
C:\>python -V
Python 3.7.3

C:\>conda -V
conda 4.6.14
```

## 仮想環境を作成
```bash
C:\>conda create -n myenv python=3.7.3
```

<details><summary>実行ログ</summary><div>

```bash
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: C:\Miniconda3\envs\myenv

  added / updated specs:
    - python=3.7.3


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pip-19.1.1                 |           py37_0         1.8 MB
    python-3.7.3               |       h8c8aaf0_1        17.8 MB
    setuptools-41.0.1          |           py37_0         680 KB
    sqlite-3.28.0              |       he774522_0         945 KB
    vs2015_runtime-14.15.26706 |       h3a45250_4         2.4 MB
    wheel-0.33.4               |           py37_0          57 KB
    ------------------------------------------------------------
                                           Total:        23.6 MB

The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/win-64::ca-certificates-2019.1.23-0
  certifi            pkgs/main/win-64::certifi-2019.3.9-py37_0
  openssl            pkgs/main/win-64::openssl-1.1.1b-he774522_1
  pip                pkgs/main/win-64::pip-19.1.1-py37_0
  python             pkgs/main/win-64::python-3.7.3-h8c8aaf0_1
  setuptools         pkgs/main/win-64::setuptools-41.0.1-py37_0
  sqlite             pkgs/main/win-64::sqlite-3.28.0-he774522_0
  vc                 pkgs/main/win-64::vc-14.1-h0510ff6_4
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.15.26706-h3a45250_4
  wheel              pkgs/main/win-64::wheel-0.33.4-py37_0
  wincertstore       pkgs/main/win-64::wincertstore-0.2-py37_0


Proceed ([y]/n)? y

Downloading and Extracting Packages
setuptools-41.0.1    | 680 KB    | ############################################################# | 100%
python-3.7.3         | 17.8 MB   | ############################################################# | 100%
pip-19.1.1           | 1.8 MB    | ############################################################# | 100%
sqlite-3.28.0        | 945 KB    | ############################################################# | 100%
wheel-0.33.4         | 57 KB     | ############################################################# | 100%
vs2015_runtime-14.15 | 2.4 MB    | ############################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > activate myenv
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
```
</div></details>

## 仮想環境を起動
```bash
C:\>activate myenv

(myenv) C:\>
```

毎回コマンドを叩くのは面倒なのでバッチを作る
プロジェクトを作りたいディレクトリにバッチを置いて叩く

```bash:C&#058;\Projects\activate-myenv.bat
@echo off
cmd /k "activate myenv"
```

```bash:叩くとこうなる
(myenv) C:\Projects>
```


# Djangoをインストール
```bash
(myenv) C:\Projects>pip install django==2.2.1
```
<details><summary>実行ログ</summary><div>

```bash:
Collecting django==2.2.1
  Downloading https://files.pythonhosted.org/packages/b1/1d/2476110614367adfb079a9bc718621f9fc8351e9214e1750cae1832d4090/Django-2.2.1-py3-none-any.whl (7.4MB)
     |████████████████████████████████| 7.5MB 544kB/s
Collecting pytz (from django==2.2.1)
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
     |████████████████████████████████| 512kB 467kB/s
Collecting sqlparse (from django==2.2.1)
  Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Installing collected packages: pytz, sqlparse, django
Successfully installed django-2.2.1 pytz-2019.1 sqlparse-0.3.0
```
</div></details>

## プロジェクトを作成
```bash
(myenv) C:\Projects>django-admin startproject myproj
```

## 開発サーバを起動
```bash:プロジェクト内に移動
(myenv) C:\Projects>cd myproj
```

```bash:開発サーバを起動
(myenv) C:\Projects\myproj>python manage.py runserver localhost:8080
```
<details><summary>実行ログ</summary><div>

```bash:
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 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.
May 23, 2019 - 22:51:39
Django version 2.2.1, using settings 'myproj.settings'
Starting development server at http://localhost:8080/
Quit the server with CTRL-BREAK.
```
</div></details>

毎回コマンドを叩くのは面倒なのでバッチを作る
プロジェクト内にバッチを置いて叩く

```bash:C&#058;\Projects\myproj\runserver.bat
@echo off
cmd /k "activate myenv & python manage.py runserver localhost:8080"
```

# ウェブサイトを開く
- ```http://localhost:8080/```にアクセスする
 - ロケットが表示されてればOK

__　The install worked successfully! Congratulations!　__



# 公式ドキュメント
- [Python 3.7.3 ドキュメント](https://docs.python.org/ja/3/index.html)
 - [12. 仮想環境とパッケージ](https://docs.python.org/ja/3/tutorial/venv.html)
 - ホントは仮想環境にこっち使おうと思ったけどめんどくさそうだからやめた
- [Django 2.2 ドキュメント](https://docs.djangoproject.com/ja/2.2/)