LoginSignup
3
3

More than 5 years have passed since last update.

WindowsにDjangoの環境を作る

Last updated at Posted at 2018-05-03

Windows Subsystem for LinuxにUbuntuをインストーしてPython3とDjangoをインストールしてWEBアプリを動作させるまでの手順です。

DjangoのWebアプリは本番環境ではDBにMariaDBを使用するので、ここでもインストールします。

環境

Windows10 バージョン1709
Ubuntu16.4
Python3
Django2.0

Windows Subsystem for LinuxとUbuntuのインストール

こちらのページを参照させていただきました。
Windows Subsystem for LinuxからUbuntuをアンインストール

バージョン情報はこちら

NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

バージョンの確認方法はこちらのページに。
Ubuntuのバージョン確認

sudoのパスワード入力を解除する方法はこちら。
sudo のパスワードを入力なしで使うには

開発ツールのインストール

Pythonモジュールのインストールでgccが必要だったりするので開発ツールパッケージをインストールしておきます。

$ sudo apt install build-essential

結構時間かかる・・・

Python3のインストール

最初からPython 3.5.2が入っていました。

$ python3 --version
Python 3.5.2

以前にはPython3って入っていなかったような・・・Ubuntuがアップデートされたりしたのかな?

venv環境作成

venvの環境を作ろうとするとエラーになります。

$ python3 -m venv venv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/mnt/c/prj/sao/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

以前自分がメモしたページ
wslでpythonのvenv環境が作れない

これでvenv環境が作成されpipコマンドもインストール出来ました。

Pythonパッケージのインストール

$ pip3 install -r requirements.txt

エラーで止まりました

    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat
 -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R
-DLDAPMODULE_VERSION=3.0.0 -DLDAPMODULE_AUTHOR=python-ldap project -DLDAPMODULE_LICENSE=Python style -IModules -I/usr/in
clude/python3.5m -c Modules/LDAPObject.c -o build/temp.linux-x86_64-3.5/Modules/LDAPObject.o
    In file included from Modules/LDAPObject.c:8:0:
    Modules/constants.h:7:18: fatal error: lber.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

lber.hがないよって言ってますね。どうやらpython_ldapパッケージで必要なようです。
こちらに答えがありました。このページではpython-devをインストールしてますがpython3-devをインストールする必要があります。

I can't install python-ldap

$ sudo apt install libsasl2-dev python3-dev libldap2-dev libssl-dev

MariaDBのインストール

$ sudo apt install mariadb-server
$ sudo mysql_secure_installation
$ sudo service mysql start

そのほかパッケージインストール

sudo apt install libcairo2-dev

終わり

以上でWSLのUbuntuにDjangoの環境構築は終了です。

3
3
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
3
3