본문 바로가기
python3/django

CentOS7 + django 설치하기

by 2세1의 행복한 개발 2020. 7. 17.
반응형

안녕하세요. 

오늘은 python 장고를 설치해보겠습니다

django version 은 3.0.8입니다

 

1. pip 설치

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

설치 확인

pip3 --version

2. virtualenv (가상머신) 설치

pip3 install virtualenv virtualenvwrapper
vi ~/.bashrc

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=' -p /usr/bin/python3 '
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

//바로적용
source .bashrc

3. django 설치

pip3 install django

프로젝트 생성

django-admin startproject 프로젝트명

4. django 웹서버 실행

./manage.py runserver

한번에 되면 참 좋으나

가끔 이런 에러가 발생합니다

Traceback (most recent call last):
  File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/models/base.py", line 121, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/models/base.py", line 325, in add_to_class
    value.contribute_to_class(cls, name)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/models/options.py", line 208, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/utils.py", line 207, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 68, in <module>
    check_sqlite_version()
  File "/root/.virtualenvs/Allbaleun/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 65, in check_sqlite_version
    raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

잘 읽어보면 SQLite 3.8.3 or later is required (found 3.7.17).

sqlite 버전이 낮아서 발생한 오류였습니다

 

5. sqlite version update

다운로드

curl -O https://sqlite.org/2020/sqlite-autoconf-3320300.tar.gz
// 압축해제
tar -xvzf sqlite-autoconf-3320300.tar.gz

configure

sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations

에러발생!

configure: error: in `/root/sqlite-autoconf-3320300':
configure: error: no acceptable C compiler found in $PATH

에러는 gcc가 없다는 에러였어요

gcc 설치

yum -y install gcc 

다시 설치

sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make install

파이썬 접속하여 버전 갱신

python3

import sqlite3
sqlite3.sqlite_version

6. 웹서버 실행

sudo nohup python3 manage.py runserver 0.0.0.0:8000

HOSTS 에러 발생

생성한 프로젝트에 settings.py 파일에 ALLOWED_HOSTS를 입력해줘야한다

이렇게 화면이 나온다면 프로젝트 생성을 성공한 것 입니다

'python3 > django' 카테고리의 다른 글

django - That port is already in use  (0) 2020.07.17

댓글