1. Python 설치

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar xvzf Python-3.6.0.tgz
cd Python-3.6.0
./configure --includedir=/usr/include <- make file 만들기
make <- compile
make install <- 설치

실제설치되는 경로 : /usr/local/lib/python3.6/

 

2. 기존 설치된 Python을 새로 설치한 Python3로 연결

# which python
/usr/bin/python

# ls -al /usr/bin/python*
lrwxrwxrwx 1 root root    7 Oct  8 01:39 /usr/bin/python -> python2
lrwxrwxrwx 1 root root    9 Oct  8 01:39 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7136 Sep 16 07:38 /usr/bin/python2.7

# unlink /usr/bin/python
# which python3
/usr/local/bin/python3

# ln -s /usr/local/bin/python3 /usr/bin/python
# ls -al /usr/bin/python*
lrwxrwxrwx 1 root root   22 Feb 26 18:12 /usr/bin/python -> /usr/local/bin/python3
lrwxrwxrwx 1 root root    9 Oct  8 01:39 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7136 Sep 16 07:38 /usr/bin/python2.7

# python -V
Python 3.6.0

 

3. 실행환경 만들기

[root@localhost home]# pip
bash: pip: command not found...


# yum install python-pip
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

# vi /usr/bin/yum
----------------------------------
#!/usr/bin/python2.7 <- python을 python2.7로 수정


# yum install python-pip <- 설치안되었다.

-- yum epel(Extra Packages for Enterprise Linux) 저장소 추가
# yum repolist              <- 목록에 epel없다.
# rpm -qa epel-release      <- 확인
# yum list epel-release     <- 확인
# yum install epel-release  <- 설치 (설치중 구문오류 발생하면 위 처럼 vi로 python명 변경)
# yum repolist              <- 목록에 epel있다.


# yum install python-pip <- 다시 설치 시도
# which pip
/usr/bin/pip

# yum install python-tools
-- 3번의 여기까지는 잘 안되었다. 다음 줄 부터 되었다. 나중에 확인필요

# yum install python34-setuptools <- pip3설치
# which pip3
/usr/bin/pip3

# ls -al /usr/bin/pip*
-rwxr-xr-x 1 root root 284 Feb 27 15:53 /usr/bin/pip
-rwxr-xr-x 1 root root 207 Feb 26 23:15 /usr/bin/pip2
-rwxr-xr-x 1 root root 207 Feb 26 23:15 /usr/bin/pip2.7
-rwxr-xr-x 1 root root 286 Feb 27 15:53 /usr/bin/pip3
-rwxr-xr-x 1 root root 290 Feb 27 15:53 /usr/bin/pip3.5
-rwxr-xr-x 1 root root 370 Jan 20 03:13 /usr/bin/pip3.6
# pip3.6 -V
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
# pip3.5 -V
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)
# pip3 -V
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)


-- virtualenv설치, 가상환경 만들기

# pip3.6 install virtualenv
# virtualenv venv          <- virtualenv venv --python=python3.6 이렇게 명시 할 수도 있다.
# source venv/bin/activate <- 가상환경 시작
(venv) # pip list


4. Django 설치 (가상환경에서 설치)

(venv) # pip install Django <- 삭제는 pip uninstall Django
Collecting Django
  Using cached Django-1.10.5-py2.py3-none-any.whl
Installing collected packages: Django
Successfully installed Django-1.10.5
(venv) # python
Python 3.6.0 (default, Jan 19 2017, 16:59:54) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version());
1.10.5


(venv) [root@localhost home]# ls
anzinda76  Python-3.6.0  svn  venv


5. Web Root Directory 만들기

(venv) [root@localhost home]# mkdir webapp
(venv) [root@localhost home]# ls
anzinda76  Python-3.6.0  svn  venv  webapp
(venv) [root@localhost home]# cd webapp
(venv) [root@localhost webapp]# ls


6. 프로젝트 생성

(venv) [root@localhost webapp]# django-admin.py startproject mysite
(venv) [root@localhost webapp]# ls
mysite


7. 서버시작

(venv) [root@localhost webapp]# cd mysite
(venv) [root@localhost mysite]# ls
manage.py  mysite
(venv) [root@localhost mysite]# python manage.py runserver 0.0.0.0:8000 &
[1] 50342
(venv) [root@localhost mysite]# Performing system checks...

System check identified no issues (0 silenced).

You have 13 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.

February 27, 2017 - 07:26:52
Django version 1.10.5, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
^M
(venv) [root@localhost mysite]# deactivate <- 가상환경 종료 

 

-- 브라우저에서
http://linux.anzinda.com:8000/ <- 안된다.
http://192.168.85.128:8000/    <- 안된다.
http://127.0.0.1:8000/         <- 로컬에서만 된다.


"DisallowedHost at /" 에러발생

(venv) [root@localhost mysite]# vi /home/webapp/mysite/mysite/settings.py
-------------------------------------
ALLOWED_HOSTS = [] -> ALLOWED_HOSTS = ['linux.anzinda.com','192.168.85.128',]

:wq! <- 하면 자동 재시작된다.

다시 브라우저에서 열면 된다.

 

8. SQLite 설치

# rpm -qa | grep sql
sqlite-3.7.17-8.el7.x86_64

# yum install sqlite-devel


9. Python - SQLite 연동 모듈 설치

# pip install pysqlite