Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 745. Linux / WSL 환경에 Miniconda 설치하기 [링크 복사], [링크+제목 복사],
조회: 110
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

Linux / WSL 환경에 Miniconda 설치하기

파이썬 환경에서 "virtualenv + 패키지 관리자"와 같은 개념으로 conda가 있습니다. 그 conda가 패키징된 대표 제품으로 Anaconda가 있고, Miniconda는 Anaconda의 경량화 버전이라고 보시면 됩니다. 따라서 사실상 "Miniconda + 각종 부가 패키지 = Anaconda"라고 볼 수 있습니다.

암튼, WSL 환경이라면 기본 패키지의 용량이 40GB가 넘는 Anaconda보다는 역시나 Miniconda가 좋겠죠? ^^

Installing Miniconda
; https://www.anaconda.com/docs/getting-started/miniconda/install#linux-terminal-installer

설치 방법도 간단하고 여느 리눅스랑 다를 바 없습니다.

$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

$ bash ./Miniconda3-latest-Linux-x86_64.sh

...[생략]...

Preparing transaction: done
Executing transaction: done
entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
   run the following command when conda is activated:

conda config --set auto_activate_base false

You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>>

You have chosen to not have conda modify your shell scripts at all.
To activate conda's base environment in your current shell session:

eval "$(/home/testusr/miniconda3/bin/conda shell.YOUR_SHELL_NAME hook)"

To install conda's shell functions for easier access, first activate, then:

conda init

Thank you for installing Miniconda3!
$

마지막 질문에 "yes"라고 답하지 않으면 WSL Shell 시작 시 conda가 자동으로 활성화되지 않습니다. 하지만 'no'를 선택했어도 괜찮습니다, ^^ 이런 경우에는 수작업으로 conda를 활성화시킬 수 있는데요, 기본 설치 경로가 "/home/사용자이름/miniconda3"이므로 이런 식으로 명령어를 내리면 됩니다.

// conda 활성화
testusr@testpc:~$ source ~/miniconda3/bin/activate
(base) testusr@testpc:~$

// conda 비활성화
(base) testusr@testpc:~$ conda deactivate
testusr@testpc:~$

게다가, 다음의 명령어를 내리면,

$ conda init --all

설치 시 "yes"라고 답한 것과 동일한 효과를 볼 수 있으므로 언제든 선택 가능합니다. 참고로, 위와 같은 명령어는 결국 사용자의 "~/.bashrc" 파일에 다음과 같은 내용을 추가하는 것에 불과합니다.

$ cat ~/.bashrc

# ...[생략]...

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/testusr/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/testusr/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/testusr/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/testusr/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

추가된 코드에 따라, WSL Shell 화면을 열면 자동으로 conda가 활성화된 상태로 시작합니다. (프롬프트를 통해 알 수 있습니다.)

(base) testusr@testpc:~$

원한다면, 저렇게 추가된 Shell 코드를 .bashrc 파일을 편집해 삭제하는 것도 가능하고, 직접 삭제하는 번거로운 과정을 대신해 주는 conda 명령어를 이용해도 됩니다.

(base) testusr@testpc:~$ conda init --reverse

또는, .bashrc 파일의 코드는 그대로 두면서 WSL Shell 시작 시 conda 활성화를 on/off 하는 것도 가능하므로 굳이 삭제까지 할 필요는 없을 것입니다.

// WSL Shell 시작 시 conda 비활성화
(base) testusr@testpc:~$ conda config --set auto_activate_base false

// WSL Shell 시작 시 conda 활성화
(base) testusr@testpc:~$ conda config --set auto_activate_base true




이후 문서에 따라,

# Managing environments
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

가상 환경에 대한 CRUD도 해보고,

// 가상 환경 생성

$ conda create --name test_env
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/testusr/miniconda3/envs/test_env



Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate test_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) $

// 더욱 편리한 점은, 보통 특정 버전의 python 개발 환경을 구성하고 싶을 때 인자로 지정해 가상 환경을 만드는 것이 가능합니다.

$ conda create --name py311build python=3.11

// 가상 환경 조회

$ conda env list

# conda environments:
#
base                 * /home/testusr/miniconda3
test_env               /home/testusr/miniconda3/envs/test_env

$ conda info --envs

# conda environments:
#
base                 * /home/testusr/miniconda3
test_env               /home/testusr/miniconda3/envs/test_env

// 가상 환경 활성/패키지 설치

$ conda activate test_env
(test_env) testusr@testpc:~$

// pip를 이용한 패키지 설치 (Pip installs Python packages)
(test_env) testusr@testpc:~$ conda install pip
...[생략]...

(test_env) testusr@testpc:~$ pip install pymssql
...[생략]...

(test_env) testusr@testpc:~$ python -c 'import pymssql; print(pymssql.__version__)'
2.3.4

// conda를 이용한 패키지 설치 (whereas conda installs packages which may contain software written in any language.) 
(test_env) testusr@testpc:~$ conda install numpy
...[생략]...

(test_env) testusr@testpc:~$ python -c 'import numpy; print(numpy.__version__)'
2.2.5


// 가상 환경 비활성
(test_env) testusr@testpc:~$ conda deactivate
(base) testusr@testpc:~$


// 가상 환경 삭제
(base) testusr@testpc:~$ conda remove --name test_env --all

구성한 가상 환경을 conda-pack 도구를 이용해 tar.gz로 패키징도 해보면,

$ conda install conda-pack
$ which conda-pack
/home/testusr/miniconda3/envs/test_env/bin/conda-pack

$ conda-pack -n test_env -o test_env.tar.gz

기본적인 활용법은 모두 끝났다고 볼 수 있습니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 5/23/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13936정성태5/23/2025110개발 환경 구성: 745. Linux / WSL 환경에 Miniconda 설치하기
13935정성태5/20/2025378파이썬 - pip 사용 시 "ImportError: cannot import name 'html5lib' from 'pip._vendor'" 오류
13934정성태5/20/2025515스크립트: 77. 파이썬 - 'urllib.request' 모듈의 명시적/암시적 로딩 차이
13933정성태5/19/2025553오류 유형: 956. Visual Studio 2022가 17.12 버전부터 업데이트 되지 않는다면?
13932정성태5/18/2025623스크립트: 76. 파이썬 - Version 문자열 다루기(semver 패키지)
13931정성태5/17/20251021스크립트: 75. 파이썬 - Cython 기본 예제 및 컴파일
13930정성태5/17/2025937개발 환경 구성: 744. 파이썬 - Windows embeddable package 환경에서 외부 패키지 사용하는 방법(ex: UFO² 환경 구성)
13929정성태5/16/20251071오류 유형: 955. 파이썬 - "Windows embeddable package" REPL 환경에서 "NameError: name 'exit' is not defined"
13928정성태5/15/20251182오류 유형: 954. UFO² - "'Invalid URL (POST /v1/chat/completions/chat/completions)'"
13927정성태5/15/20251182오류 유형: 953. OpenAI - The API request of HOST_AGENT failed: OpenAI API request exceeded rate limit: Error code: 429
13926정성태5/14/20251589개발 환경 구성: 743. LLM과 윈도우의 만남 - Desktop AgentOS UFO² 기본 환경 구성
13925정성태5/12/20251691닷넷: 2333. C# - (Console 유형의 프로젝트에서) Clipboard 연동파일 다운로드1
13924정성태5/8/20251443닷넷: 2332. C# - (JetBrains Omea Reader 대상으로) 런타임 시에 메서드 가로채기 [2]파일 다운로드1
13923정성태5/5/20251256스크립트: 74. 파이썬 - C# - Python.NET의 RunSimpleScript, Exec, Eval 차이점파일 다운로드1
13922정성태5/3/20251363스크립트: 73. 파이썬 - Windows embeddable package 버전에서 tkinter 환경 구성
13921정성태5/3/20251630오류 유형: 952. 듀얼 채널 메모리 정렬을 지키지 않은 컴퓨터의 Windows 비정상 종료 현상(Blue Screen) [2]
13920정성태5/3/20251655오류 유형: 951. Typed DataSet 생성 중 "Failed to open a connection to the database" 오류
13919정성태5/2/20251525VS.NET IDE: 201. C# - Typed DataSet(XSD)를 위한 연결 문자열 암호화 [1]파일 다운로드1
13918정성태5/2/20251627VS.NET IDE: 200. C# - app.config 파일의 출력을 Configuration(Debug/Release)에 따라 제어하는 방법파일 다운로드1
13917정성태4/30/20251320VS.NET IDE: 199. Directory.Build.props에 정의한 속성에 대해 Condition 제약으로 값을 변경하는 방법
13916정성태4/23/20251130디버깅 기술: 221. WinDbg 분석 사례 - ASP.NET HttpCookieCollection을 다중 스레드에서 사용할 경우 무한 루프 현상 - 두 번째 이야기
13915정성태4/13/20252460닷넷: 2331. C# - 실행 시에 메서드 가로채기 (.NET 9)파일 다운로드1
13914정성태4/11/20252856디버깅 기술: 220. windbg 분석 사례 - x86 ASP.NET 웹 응용 프로그램의 CPU 100% 현상 (4)
13913정성태4/10/20251693오류 유형: 950. Process Explorer - 64비트 윈도우에서 32비트 프로세스의 덤프를 뜰 때 "Error writing dump file: Access is denied." 오류
13912정성태4/9/20251402닷넷: 2330. C# - 실행 시에 메서드 가로채기 (.NET 5 ~ .NET 8)파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...