아무것도 모른채 필요한 라이브러리를 계속 Base에 설치하다보면, 시간이 지남에 따라 경고(warning)문구나 각 라이브러리들의 의존성(dependancy) 문제로 인해 다양한 오류들을 만나 삽질한 기억이 있을 것이다.
또한 프로젝트마다 활용하는 다양한 라이브러리(특히 tensorflow 같은 경우)끼리 호환문제도 적지 않다.
다른 환경(컴퓨터, 서버 등)에서 동일한 작업을 하려면 이 환경을 똑같이 언제 다 만들까?
이런 작업 환경들을 프로젝트별로 관리하고(like 폴더 개념) 공유도 할 수 있도록 도와주는 것이 바로 가상환경이다.
특징
아나콘다의 부트스트랩 버전
Conda, Python, 의존하는 패키지 및 pip, zlib 및 기타 몇 가지를 포함한 소수의 기타 유용한 패키지만 포함
기본적인 요구 사항만 포함하고 있으며, 원하는 패키지를 그때그때 설치하여 사용
이런 사람들에게 추천
아나콘다를 설치한 시간이나 디스크 공간이 없을때
파이썬과 conda 명령에 빠르게 액세스 가능
특징
1500개가 넘는 데이터 분석 패키지를 포함
회사 내에서도 상업용으로 무료로 사용할 수 있다
여러 가지 파이썬 배포판 중 가장 후발주자이지만 가장 완성도가 뛰어남(사실상의 표준 배포판)
아나콘다는 패키지 의존성을 관리해주므로 가상환경에 따라 독립적으로 패키지 관리 가능
각 프로젝트 별로 개발 환경을 구성 가능
대표적 툴 : panda, numpy, scipy, sklearn, matplotlib, Jupyter Notebook
이런 사람들에게 추천
콘다 또는 파이썬을 처음 사용함
각 패키지를 따로 설치하기 싫음
❯ conda config --add channels conda-forge
❯ conda config --set channel_priority strict
❯ conda config --show channels
channels:
- conda-forge
- defaults
1. 가상환경 생성하기
[SSL/TLS버전 설정을 변경 (CondaSSLError)]
conda config --set ssl_verify no
❯ conda create -n python_39 python=3.9.15
Channels:
- conda-forge
- defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/chani22/miniconda3/envs/python_39
added / updated specs:
- python=3.9.15
The following packages will be downloaded:
package | build
---------------------------|-----------------
_libgcc_mutex-0.1 | conda_forge 3 KB conda-forge
_openmp_mutex-4.5 | 2_gnu 23 KB conda-forge
...
Proceed ([y]/n)?
Downloading and Extracting Packages:
...
2. 가상환경 활성화 하기
❯ conda activate python_39
3. 패키지 설치
❯ pip install jupyter notebook ipykernel
Collecting jupyter
Downloading jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting notebook
Downloading notebook-7.0.6-py3-none-any.whl.metadata (10 kB)
Collecting ipykernel
Downloading ipykernel-6.28.0-py3-none-any.whl.metadata (6.0 kB)
Collecting qtconsole (from jupyter)
Downloading qtconsole-5.5.1-py3-none-any.whl.metadata (5.1 kB)
...
4. 가상환경과 Jupyter Notebook 연결
❯ python -m ipykernel install --user --name python_39 --display-name python_39
Installed kernelspec python_39 in /home/chani22/.local/share/jupyter/kernels/python_39
5. Jupyter Notebook 실행
❯ jupyter notebook
[W 2024-01-11 00:29:46.408 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[W 2024-01-11 00:29:46.429 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2024-01-11 00:29:46.429 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-01-11 00:29:46.432 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-01-11 00:29:46.435 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-01-11 00:29:46.439 ServerApp] notebook | extension was successfully linked.
[I 2024-01-11 00:29:46.440 ServerApp] Writing Jupyter server cookie secret to /home/chani22/.local/share/jupyter/runtime/jupyter_cookie_secret
[I 2024-01-11 00:29:46.604 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-01-11 00:29:46.618 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-01-11 00:29:46.619 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-01-11 00:29:46.620 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-01-11 00:29:46.621 LabApp] JupyterLab extension loaded from /home/chani22/miniconda3/envs/python_39/lib/python3.9/site-packages/jupyterlab
[I 2024-01-11 00:29:46.621 LabApp] JupyterLab application directory is /home/chani22/miniconda3/envs/python_39/share/jupyter/lab
[I 2024-01-11 00:29:46.622 LabApp] Extension Manager is 'pypi'.
[I 2024-01-11 00:29:46.624 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-01-11 00:29:46.625 ServerApp] notebook | extension was successfully loaded.
[I 2024-01-11 00:29:46.626 ServerApp] Serving notebooks from local directory: /srv/workspace/python_39
[I 2024-01-11 00:29:46.626 ServerApp] Jupyter Server 2.12.3 is running at:
[I 2024-01-11 00:29:46.626 ServerApp] http://localhost:8888/tree?token=5ed486a3d676270879b3684991a11b4932c981c265dddef4
[I 2024-01-11 00:29:46.626 ServerApp] http://127.0.0.1:8888/tree?token=5ed486a3d676270879b3684991a11b4932c981c265dddef4
[I 2024-01-11 00:29:46.626 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-01-11 00:29:47.025 ServerApp]
To access the server, open this file in a browser:
file:///home/chani22/.local/share/jupyter/runtime/jpserver-4428-open.html
Or copy and paste one of these URLs:
http://localhost:8888/tree?token=5ed486a3d676270879b3684991a11b4932c981c265dddef4
http://127.0.0.1:8888/tree?token=5ed486a3d676270879b3684991a11b4932c981c265dddef4
[I 2024-01-11 00:29:47.041 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server