Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 745. Linux / WSL 환경에 Miniconda 설치하기 [링크 복사], [링크+제목 복사],
조회: 99
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 91  92  93  94  95  96  97  98  99  100  101  102  [103]  104  105  ...
NoWriterDateCnt.TitleFile(s)
11371정성태11/25/201720308오류 유형: 432. Hyper-V 가상 스위치 생성 시 Failed to connect Ethernet switch port 0x80070002 오류 발생
11370정성태11/25/201720324오류 유형: 431. Hyper-V의 Virtual Switch 생성 시 "External network" 목록에 특정 네트워크 어댑터 항목이 없는 경우
11369정성태11/25/201722286사물인터넷: 12. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드 및 마우스로 쓰는 방법 (절대 좌표, 상대 좌표, 휠) [1]
11368정성태11/25/201727826.NET Framework: 699. UDP 브로드캐스트 주소 255.255.255.255와 192.168.0.255의 차이점과 이를 고려한 C# UDP 서버/클라이언트 예제 [2]파일 다운로드1
11367정성태11/25/201727980개발 환경 구성: 337. 윈도우 운영체제의 route 명령어 사용법
11366정성태11/25/201719678오류 유형: 430. 이벤트 로그 - Cryptographic Services failed while processing the OnIdentity() call in the System Writer Object.
11365정성태11/25/201721528오류 유형: 429. 이벤트 로그 - User Policy could not be updated successfully
11364정성태11/24/201723739사물인터넷: 11. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법 (절대 좌표) [2]
11363정성태11/23/201723823사물인터넷: 10. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스 + 키보드로 쓰는 방법 (두 번째 이야기)
11362정성태11/22/201719952오류 유형: 428. 윈도우 업데이트 KB4048953 - 0x800705b4 [2]
11361정성태11/22/201722922오류 유형: 427. 이벤트 로그 - Filter Manager failed to attach to volume '\Device\HarddiskVolume??' 0xC03A001C
11360정성태11/22/201722864오류 유형: 426. 이벤트 로그 - The kernel power manager has initiated a shutdown transition.
11359정성태11/16/201722338오류 유형: 425. 윈도우 10 Version 1709 (OS Build 16299.64) 업그레이드 시 발생한 문제 2가지
11358정성태11/15/201727189사물인터넷: 9. Visual Studio 2017에서 Raspberry Pi C++ 응용 프로그램 제작 [1]
11357정성태11/15/201727573개발 환경 구성: 336. 윈도우 10 Bash 쉘에서 C++ 컴파일하는 방법
11356정성태11/15/201729273사물인터넷: 8. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스 + 키보드로 쓰는 방법 [4]
11355정성태11/15/201724758사물인터넷: 7. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법 [2]파일 다운로드2
11354정성태11/14/201729274사물인터넷: 6. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드로 쓰는 방법 [8]
11353정성태11/14/201726413사물인터넷: 5. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 이더넷 카드로 쓰는 방법 [1]
11352정성태11/14/201722528사물인터넷: 4. Samba를 이용해 윈도우와 Raspberry Pi간의 파일 교환 [1]
11351정성태11/7/201725666.NET Framework: 698. C# 컴파일러 대신 직접 구현하는 비동기(async/await) 코드 [6]파일 다운로드1
11350정성태11/1/201721722디버깅 기술: 108. windbg 분석 사례 - Redis 서버로의 호출을 기다리면서 hang 현상 발생
11349정성태10/31/201722221디버깅 기술: 107. windbg - x64 SOS 확장의 !clrstack 명령어가 출력하는 Child SP 값의 의미 [1]파일 다운로드1
11348정성태10/31/201718564디버깅 기술: 106. windbg - x64 역어셈블 코드에서 닷넷 메서드 호출의 인자를 확인하는 방법
11347정성태10/28/201722177오류 유형: 424. Visual Studio - "클래스 다이어그램 보기" 시 "작업을 완료할 수 없습니다. 해당 인터페이스를 지원하지 않습니다." 오류 발생
11346정성태10/25/201718740오류 유형: 423. Windows Server 2003 - The client-side extension could not remove user policy settings for 'Default Domain Policy {...}' (0x8007000d)
... 91  92  93  94  95  96  97  98  99  100  101  102  [103]  104  105  ...