티스토리 뷰

python

conda 초간단 매뉴얼

게으른 the lazy 2024. 8. 20. 01:22

https://towardsdatascience.com/managing-project-specific-environments-with-conda-b8b50aa8be0e

 

 

 

conda 사용법을 간단히 정리해보았다.

이 글 작성에 도움 주신 코봉님께 감사 말씀 드립니다.

 


 

 

conda create -n example

  : example이라는 이름의 가상환경을 만듦
  : -n 대신 --name이라고 써도 됨
  : 비어있는 가상환경이 만들어지며, 아무것도 - 파이썬도 - 설치되지 않음

 

conda create -n example python

  : 가상환경 만들면서 파이썬도 같이 설치
  : 파이썬 외에도 pip, tk, sqlite 포함해서 10여 가지가 자동으로 설치됨
  : 아래는 2024년 8월 20일 기준, python 설치 시 같이 설치되는 패키지 목록임

The following NEW packages will be INSTALLED:

  bzip2              pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6
  ca-certificates    pkgs/main/win-64::ca-certificates-2024.7.2-haa95532_0
  expat              pkgs/main/win-64::expat-2.6.2-hd77b12b_0
  libffi             pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
  openssl            pkgs/main/win-64::openssl-3.0.14-h827c3e9_0
  pip                pkgs/main/win-64::pip-24.2-py312haa95532_0
  python             pkgs/main/win-64::python-3.12.4-h14ffc60_1
  setuptools         pkgs/main/win-64::setuptools-72.1.0-py312haa95532_0
  sqlite             pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
  tk                 pkgs/main/win-64::tk-8.6.14-h0416ee5_0
  tzdata             pkgs/main/noarch::tzdata-2024a-h04d1e81_0
  vc                 pkgs/main/win-64::vc-14.40-h2eaa2aa_0
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.40.33807-h98bb1dd_0
  wheel              pkgs/main/win-64::wheel-0.43.0-py312haa95532_0
  xz                 pkgs/main/win-64::xz-5.4.6-h8cc25b3_1
  zlib               pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1 

 

 

conda create -n example python=3.12.0

  : 가상환경 만들면서 파이썬도 같이 설치하되, 파이썬 버전은 3.12.0으로 함

conda search <package_name>

  : 설치 가능한 패키지 버전을 보여줌
  : python, numpy, matplotlib 등 패키지 이름을 넣으면 됨
  : conda create로 가상환경 만들 때 패키지의 버전을 선택하지 않으면 최신 버전으로 설치

conda create -n example python numpy

  : 가상환경 만들면서 파이썬과 넘파이도 같이 설치

conda activate example

  : example이라는 이름의 가상환경을 활성화 함
  : 프롬프트가 (example)로 시작하도록 바뀜

conda list

  : 현재 가상환경에 설치된 패키지 목록을 보여줌

conda install <package_name>

  : 현재 가상환경에 패키지를 설치
  : 상기한 방법대로 버전을 지정할 수 있음

conda install <package_name> -y

  : Proceed ([y]/n)?을 스킵

conda update <package_name>

  : 패키지 업데이트

conda remove <package_name>

  : 현재 가상환경에서 패키지 삭제
  : conda uninstall이라고 써도 됨 (둘은 서로의 alias임)
  : 이때 삭제할 패키지에 depend 하는 패키지도 같이 삭제됨

 

conda info

  : 현재 가상환경의 정보를 보여줌

conda env list

  : 만들어져 있는 가상환경들을 보여줌

conda list -n example

  : example 가상환경에 설치되어 있는 패키지 목록을 보여줌

conda install -n example <package_name>

  : example 가상환경에 패키지 설치
  

conda remove -n example <package_name>

  : example 가상환경에서 패키지 삭제

conda remove -n example --all

  : example 가상환경을 삭제함

conda create --clone example -n example2

  : example을 복제해서 example2를 만듦

conda <command> -h

  : command의 도움말 보여줌
  : -h 대신 --help라고 써도 됨



위에서 만든 가상환경을 vscode에서 사용하는 방법
  : ctrl + shift + p
  : Python: Select intepreter 선택
  : 목록에서 선택하거나, 없으면 Enter interpreter path...를 눌러서 path 지정
  : 활성화된 가상환경은 창 우하단에 ('<env_name>': conda)로 표시됨

 


참고
  : https://dojang.io/mod/page/view.php?id=2470

댓글