갈루아의 반서재

 

아나콘다 가상환경을 활성화시킨 상황에서 다음과 같이 Django 설치 및 프로젝트를 시작하였다. 

(tfquantum) founder@hilbert:~$ pip install Django==3.0.5
Defaulting to user installation because normal site-packages is not writeable
Collecting Django==3.0.5
  Downloading Django-3.0.5-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 2.7 MB/s
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 791 kB/s
Requirement already satisfied: pytz in /usr/lib/python3/dist-packages (from Django==3.0.5) (2018.3)
Collecting asgiref~=3.2
  Downloading asgiref-3.2.7-py2.py3-none-any.whl (19 kB)
Installing collected packages: sqlparse, asgiref, Django
Successfully installed Django-3.0.5 asgiref-3.2.7 sqlparse-0.3.1
(tfquantum) founder@hilbert:~$ django-admin startproject analytics_project

하지만, 다음과 같이 실행을 하면 임포트 에러가 발생한다.

ImportError: Couldn't import Django. Are you sure it is installed and available on your PYTHONPATH environmen                                                                                                                                 t variable? Did you forget to activate a virtual environment?

pip show 를 통해 정상적으로 설치되었음을 확인할 수 있다. 하지만, 문제는 이 설치에 사용된 pip 가 global pip 라는 것이다. 아나콘다 환경에서 pip 패키지 설치시에는 전체 경로를 명시해줘야 한다. 

(tfquantum) founder@hilbert:~/analytics_project$ pip show Django
Name: Django
Version: 3.0.5
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD
Location: /home/founder/.local/lib/python3.6/site-packages
Requires: sqlparse, pytz, asgiref
Required-by:
(tfquantum) founder@hilbert:~/analytics_project$
(tfquantum) founder@hilbert:~/analytics_project$ which pip
/home/founder/.local/bin/pip

conda list 로 조회해보면 Django 관련하여 설치된 라이브러리가 없다고 나온다.

 

(tfquantum) founder@hilbert:~/analytics_project$ conda list Django
# packages in environment at /home/founder/anaconda3/envs/tfquantum:
#
# Name                    Version                   Build  Channel

 전체 경로를 사용한 아나콘다 환경내 pip 패키지 설치는 다른 포스팅에서 다루기로 하고, 여기서는 conda install 을 통해 Django 를 설치해서 마무리하자.

(tfquantum) founder@hilbert:~/analytics_project$ conda install -c anaconda django
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/founder/anaconda3/envs/tfquantum

  added / updated specs:
    - django


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    asgiref-3.2.5              |             py_0          21 KB  anaconda
    ca-certificates-2020.1.1   |                0         132 KB  anaconda
    certifi-2019.11.28         |           py37_1         156 KB  anaconda
    django-3.0.3               |             py_0         3.6 MB  anaconda
    pytz-2019.3                |             py_0         231 KB  anaconda
    sqlparse-0.3.0             |             py_0          31 KB  anaconda
    ------------------------------------------------------------
                                           Total:         4.1 MB

The following NEW packages will be INSTALLED:

  asgiref            anaconda/noarch::asgiref-3.2.5-py_0
  django             anaconda/noarch::django-3.0.3-py_0
  pytz               anaconda/noarch::pytz-2019.3-py_0
  sqlparse           anaconda/noarch::sqlparse-0.3.0-py_0

The following packages will be UPDATED:

  openssl              pkgs/main::openssl-1.1.1e-h7b6447c_0 --> anaconda::openssl-1.1.1-h7b6447c_0

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates                                 pkgs/main --> anaconda
  certifi                                         pkgs/main --> anaconda


Proceed ([y]/n)? y


Downloading and Extracting Packages
django-3.0.3         | 3.6 MB    | ################################################################# | 100%
certifi-2019.11.28   | 156 KB    | ################################################################# | 100%
ca-certificates-2020 | 132 KB    | ################################################################# | 100%
pytz-2019.3          | 231 KB    | ################################################################# | 100%
asgiref-3.2.5        | 21 KB     | ################################################################# | 100%
sqlparse-0.3.0       | 31 KB     | ################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(tfquantum) founder@hilbert:~/analytics_project$

Django 3.0.3 이 설치되었다.

(tfquantum) founder@hilbert:~/analytics_project$ conda list Django
# packages in environment at /home/founder/anaconda3/envs/tfquantum:
#
# Name                    Version                   Build  Channel
django                    3.0.3                      py_0    anaconda

마이그레이션 후 실행해보자.

(tfquantum) founder@hilbert:~/analytics_project$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK
(tfquantum) founder@hilbert:~/analytics_project$ python manage.py runserver 0.0.0.0:8080
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 04, 2020 - 08:51:45
Django version 3.0.3, using settings 'analytics_project.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CONTROL-C.
[04/Apr/2020 08:51:52] "GET / HTTP/1.1" 200 16351

실행된 모습이다. 정상적으로 작동함을 볼 수 있다.