sh파일(non-interactive shell script)에서 conda 가상환경 activation!

2021. 12. 5. 20:09·Programming
728x90
728x90

 

ubuntu에서 셀스크립트를 작성하던 중, conda activate 가 동작하지 않던 문제가 발생.

  • non-interactive shell script 의 경우 ~/.bashrc 를 로드하지 않아서 이를 통한 초기화가 수행되지 않음.
  • cron 등을 이용한 경우가 전형적인 non-interactive shell script 임.

셀 스크립트 작성방법

가상환경 이름이 test라고 한다면, 다음과 같이 처리해야 함.

#!/bin/bash
source ~/miniconda3/etc/profile.d/conda.sh
conda activate test
이하생략.

위의 경우는 miniconda를 설치한 경우이며 anaconda인 경우 첫번째 줄을 다음과 같이 변경.

#!/bin/bash
source ~/anaconda3/etc/profile.d/conda.sh
conda activate test
이하생략.

주의사항

주의할 점은 shebang line으로 cond init이 이루어진 shell을 올바르게 지정해야한다.

  • conda activate는 셀함수이기 때문에 셀이 다르면 동작하지 않음.
  • 원래 로그인해서 interactive shell에서 사용하던 shell을 지정해야함.

https://ds31x.tistory.com/3

 

[Shell] env and Shebang line

env 명령어는 주로environment variable들을 확인하거나특정 명령어 수행할 때 특정 environment variable을 지정해주는데 사용된다.The env command allows youto display your current environment or run a specified commandin a chan

ds31x.tistory.com


같이 보면 좋은 자료들

https://ds31x.tistory.com/212

 

[Env] conda 환경설정 스크립트: conda init

환경변수 PATH에 conda를 추가하지 않도록 설치하고 나서,터미널 등에서 conda를환경변수 PATH 에 추가하려면, conda prompt 나 conda가 설치된 경로로 이동한 이후, 다음을 수행하면 됨 (Windows의 경우, anaco

ds31x.tistory.com

 

728x90

'Programming' 카테고리의 다른 글

Paradigm (패러다임)  (0) 2022.07.21
[Python] 현재 사용 중인 Python 및 패키지의 실제 경로 확인하기.  (2) 2022.07.18
[Error: Tensorboard] ImportError: cannot import name 'Mapping' from 'collections'  (1) 2022.05.18
[ML] Entropy, KL-Divergence, and Cross-entropy  (0) 2022.05.12
[Conda] miniconda의 기본 채널 변경 : conda-forge  (3) 2022.04.05
'Programming' 카테고리의 다른 글
  • [Python] 현재 사용 중인 Python 및 패키지의 실제 경로 확인하기.
  • [Error: Tensorboard] ImportError: cannot import name 'Mapping' from 'collections'
  • [ML] Entropy, KL-Divergence, and Cross-entropy
  • [Conda] miniconda의 기본 채널 변경 : conda-forge
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (787)
      • Private Life (15)
      • Programming (206)
        • DIP (116)
        • ML (35)
      • Computer (120)
        • CE (54)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (368)
        • Signals and Systems (115)
        • Math (176)
        • Linear Algebra (33)
        • Physics (43)
        • 인성세미나 (1)
      • 정리필요. (61)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (7)
        • PET Study 2009 (1)
        • 방사선 장해방호 (5)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    linear algebra
    signals_and_systems
    opencv
    math
    Term
    fourier transform
    function
    Probability
    ML
    Programming
    SS
    signal_and_system
    Optimization
    numpy
    SIGNAL
    random
    cv2
    인허가제도
    Vector
    Python
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
sh파일(non-interactive shell script)에서 conda 가상환경 activation!
상단으로

티스토리툴바