가상환경 새로 만들때 

1. 가상환경 만들기

conda create -n <가상환경이름> python=<파이썬버전>

env list : 가상환경 목록 확인

conda activate <가상환경이름>

2. pip 설치 및 requirements.txt 설치

conda install pip

pip install -r requirements.txt (기재된 패키지 설치)

pip freeze > requirements.txt (가상환경에 설치되어있는 패키치 txt 파일로 저장)

3. jupyter-notebook 에 가상환경 연결 

pip install jupyter notebook 

pip install ipykernel

python -m ipykernel install --user --name <가상환경이름> --display-name <주피터에서 볼 이름-지정>

jupyter notebook 들어가면, new 에서도 커널 바꿀 수 있고/ 파일 들어가서도 kernel 탭 > Change kernel 에서 변경가능

4. 분석 완료 되었을때쯤 늘 requirements.txt 추출해놓고, 간략하게 파일에 대한 description 정리, 하드디스크에 넣어두기.

pip freeze > requirements.txt (가상환경에 설치되어있는 패키치 txt 파일로 저장)


기존에 있던 아나콘다 가상환경 다른곳으로 복사 옮기고 싶을때 

1. Conda env 를 yaml 파일로 export 하기 

conda activate envconda # 가상환경 이름이 envconda 일때
conda env export > envconda.yaml

2. yaml 파일로 콘다 환경 생성하기 

If you try to create anaconda environment to another machine, you should edit the envconda.yaml file's prefix to the another machine's anaconda3 directory. 

conda env create -f envconda.yaml
conda activate envconda

tip) If you encounter the "Resolve Package Not Found" error, remove the printed library list from the envconda.yaml file and re-try it. 

# 참고: 서버에서 로컬머신으로 업로드, 다운로드 하는법

다운로드 : scp  사용자명@서버주소:서버파일경로  로컬저장경로

scp user@remote.com:/home/test.txt /home/test.txt

-> 접속포트 지정 : -P 옵션 사용

-> 키 사용해 접속 : -i 옵션 사용

-> 폴더 다운로드 경우 : -r 옵션 사용 

업로드  scp  로컬파일경로  사용자명@서버주소:서버저장경로

scp /home/test.txt user@remote.com:/home/test.txt

tip) If it doesn't work for some reason, then just open the yaml file and copy&paste all library to the new file on the machine you want to use. kk


그 외

1. 가상환경 삭제 (문제 생겼을때 대비)

conda env remove -n envconda

2. 같은 머신 내에서 가상 환경 복사

conda create -n envconda_copy --clone envconda 

3. conda default version update command

conda update -n base -c defaults conda

+ Recent posts