Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 745. Linux / WSL 환경에 Miniconda 설치하기 [링크 복사], [링크+제목 복사],
조회: 15
글쓴 사람
정성태 (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)
11421정성태1/2/201820490오류 유형: 443. Visual Studio - nuget configuration is invalid
11420정성태12/30/201724573.NET Framework: 722. C# - Windows 10 운영체제의 데스크톱 앱에서 음성인식(SpeechRecognizer) 사용하는 방법 [3]파일 다운로드1
11419정성태12/23/201726792.NET Framework: 721. WebClient 타입의 ...Async 메서드 호출은 왜 await + 동기 호출 시 hang 현상이 발생할까요? [2]파일 다운로드1
11418정성태12/23/201736513.NET Framework: 720. 비동기 메서드 내에서 await 시 ConfigureAwait 호출 의미 [2]파일 다운로드1
11417정성태12/22/201722432.NET Framework: 719. Task를 포함하는 async 메서드의 동작 방식 [2]
11416정성태12/21/201719809.NET Framework: 718. AsyncTaskMethodBuilder.Create() 메서드 동작 방식 [2]
11415정성태12/21/201721638.NET Framework: 717. Task를 포함하지 않는 async 메서드의 동작 방식 [6]
11414정성태12/21/201728720.NET Framework: 716. async 메서드의 void 반환 타입 사용에 대하여파일 다운로드2
11413정성태12/20/201723236개발 환경 구성: 344. 윈도우 10 - TTS 및 음성 인식을 위한 환경 설정
11412정성태12/20/201725779.NET Framework: 715. C# - Windows 10 운영체제의 데스크톱 앱에서 TTS(SpeechSynthesizer) 사용하는 방법 [1]파일 다운로드1
11411정성태12/20/201724076사물인터넷: 15. 라즈베리 파이용 C++ 프로젝트에 SSL Socket 적용
11410정성태12/20/201736467.NET Framework: 714. SSL Socket 예제 - C/C++ 서버, C# 클라이언트 [1]파일 다운로드1
11409정성태12/18/201742505VC++: 122. 오픈 소스 라이브러리를 쉽게 빌드해 주는 "C++ Package Manager for Windows: vcpkg" [7]
11408정성태12/18/201721634.NET Framework: 713. C# - SharpDX + DXGI를 이용한 윈도우 화면 캡처 소스 코드 + Direct2D 출력 + OpenCV (2)파일 다운로드1
11407정성태12/18/201724980.NET Framework: 712. C# - SharpDX + DXGI를 이용한 윈도우 화면 캡처 소스 코드 + Direct2D 출력 + OpenCV [1]파일 다운로드1
11406정성태12/17/201747429.NET Framework: 711. C# - OpenCvSharp의 Mat 데이터 조작 방법 [5]파일 다운로드1
11405정성태12/17/201743428.NET Framework: 710. C# - OpenCvSharp을 이용한 Webcam 영상 처리 + Direct2D [1]파일 다운로드1
11404정성태12/16/201730606.NET Framework: 709. C# - OpenCvSharp을 이용한 동영상(avi, mp4, ...) 처리 + Direct2D [7]파일 다운로드1
11403정성태12/16/201732936.NET Framework: 708. C# - OpenCvSharp을 이용한 동영상(avi, mp4, ...) 처리 [3]파일 다운로드1
11402정성태12/15/201737901.NET Framework: 707. OpenCV 응용 프로그램을 C#으로 구현 - OpenCvSharp [2]파일 다운로드1
11401정성태12/15/201726530.NET Framework: 706. C# - SharpDX + DXGI를 이용한 윈도우 화면 캡처 소스 코드 + Direct2D 출력 [2]파일 다운로드1
11400정성태12/14/201729715.NET Framework: 705. C# - SharpDX + DXGI를 이용한 윈도우 화면 캡처 소스 코드 [9]파일 다운로드1
11399정성태12/13/201718243.NET Framework: 704. Win32 API의 UnionRect를 닷넷 BCL의 Rectangle.Union으로 바꿀 때 주의 사항
11398정성태12/13/201718304오류 유형: 442. ASP.NET Core Web Application (on .NET Framework) 프로젝트에서 외부 라이브러리 동적 로드 시 런타임 버전 문제파일 다운로드1
11397정성태12/12/201720992.NET Framework: 703. 양자 컴퓨팅을 위한 마이크로소프트의 Q# 언어
11396정성태12/8/201743413개발 환경 구성: 343. Visual Studio - 리눅스 용 프로젝트의 인텔리센스를 위한 헤더 파일 처리 방법 [3]
... 91  92  93  94  95  96  97  98  99  100  [101]  102  103  104  105  ...