django - 가상환경 설치 및 설정

whybein·2020년 2월 4일
0

django

목록 보기
1/13
post-thumbnail

위코드 6기 day8 2020.02.05

설정 및 설치는 모두 ubuntu 기준입니다.

1. 가상환경 설정

여러 개의 프로젝트에서 다른 버젼의 모듈을 사용하는데 각각을 기본 디렉토리에 설치하면 충돌이 일어날 수 있습니다. 그래서 파이썬은 가상환경 설정을 제공하며 각 프로젝트가 독립적인 공간을 갖고 있어 각기 쓰는 버젼의 모듈을 설치할 수 있습니다.

1.1 miniconda 설치

가상환경 프로그램 중 비교적 가벼운 miniconda를 설치해 보겠습니다.

https://docs.conda.io/en/latest/miniconda.html

위 링크에 접속 후 박스 부분의 link를 복사한 후 터미널에 아래 세 번의 명령어로 설치를 완료합니다.
wget 위링크주소

chmod -R 755 Miniconda3-latest-Linux-x86_64.sh

./Miniconda3-latest-Linux-x86_64.sh

설치가 완료된 후 $ conda 명령어를 치면 아래와 같이 뜹니다.

usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/home/ybshim/.condarc) by default.
    create       Create a new conda environment from a list of specified
                 packages.
    help         Displays a list of available conda commands and their help
                 strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda
                 environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment. [Experimental]
    search       Search for packages and display associated information. The
                 input is a MatchSpec, a query language for conda packages.
                 See examples below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

conda commands available from other packages:
  env

1.2 가상환경 설정

가상 환경 목록 보기
$ conda env list

파이썬 3.7버젼의 가상환경을 만드는 명령어입니다.
$ conda create -n "가상환경이름" python=3.7

가상환경 활성화하는 방법입니다. 활성 상태에서 원하는 프로젝트를 진행하면 됩니다.
$ conda activate "가상환경이름"

가상환경 비활성하는 방법입니다.
$ conda deactivate

가상환경 삭제하는 방법입니다.
$ conda env remove -n "가상환경이름"

2. 장고 설치

https://docs.djangoproject.com/ko/3.0/intro/tutorial01/
튜토리얼을 하기 위한 장고 설치이며 가상환경에 설치합니다. 원하는 폴더를 만들어서 설치해도 상관없습니다.

mysite라는 가상환경을 만들고 활성화합니다.
$ conda create -n "mysite" python=3.7
$ conda activate "mysite"

장고 버젼을 확인할 수 있는 명령어입니다. 가상환경이기에 찾을 수 없다고 나옵니다.
$ python -m django --version

아래 명령어로 장고를 설치합니다.
(mysite) $ python -m pip install Django

장고 버젼을 확인할 수 있습니다.
(mysite) $ python -m django --version

profile
Back-End Developer

0개의 댓글