LoginSignup
2
1

More than 5 years have passed since last update.

CentOS7 + Python3.6 + Djangoの構築

Posted at

概要

VM上のCentOS7にpython3とDjangoを入れようとした際に、参考にしたものをまとめてみる。
rootで作業。 
それ以外で作業する場合は、sudoを追加。

Python3をインストール

# これはできないかもしれない。できなかったらスルー
yum install -y https://centos7.iuscommunity.org/ius-release.rpm

yum install -y python36u python36u-libs python36u-devel python36u-pip

ここでyum installでエラーになったので、updateしてみる

yum update

やはりここでもエラーになった。

調べてみると、yumのデータベースが壊れている可能性があるので、以下を実行。

yum clean

これでinstallできるようになったので、再度実行する。

yum install -y https://centos7.iuscommunity.org/ius-release.rpm

yum install -y python36u python36u-libs python36u-devel python36u-pip

pythonを確認する。
ちなみにcenOS7 にはpython2が入っているので、python3の確認方法はこう。

$python3.6

Python 3.6.4 (default, Dec 19 2017, 14:48:12)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

    >>>


# ちなみにpython2だと

$python

Python 2.7.5 (default, Aug  4 2017, 00:39:18)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

python2系は使わないし、常にpython3.6で起動するのが面倒なので、通常使うpythonのバージョンを2系から3.6に切り替える。

ln -s /bin/python3.6 /bin/python3
unlink /bin/python
ln -s /bin/python3 /bin/python
ln -s /bin/pip3.6 /bin/pip

切り替えができたか確認する。

$python

Python 3.6.4 (default, Dec 19 2017, 14:48:12)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>>

無事に切り替わった。

Djangoのインストール

pip install django

#Djangoが入ったかどうかを確認する(django + tabキーでdjango-adminが出れば問題なし)
django-admin startproject sample

これで完了。

あとはDockerなり、Daemonで起動すれば終わり。

参考にしたサイト

CentOS 7 + python3 + Djangoの本番環境を動かしてみる
https://qiita.com/tinaba/items/01bc72c100f97438a36e

№2846 yum rpm エラーで出来ません
https://centossrv.com/bbshtml/webpatio/2846.shtml

Python3系に置き換える
http://gamsj2015.hatenablog.com/entry/2018/02/18/110419

2
1
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
2
1