pip&conda 꿀팁들

꼼댕이·2023년 9월 25일
0

python&linux

목록 보기
1/10

python package 설치를 하다보면 온갖 잡다한 에러가 있을 때가 있다... 몇개 꿀팁들을 적어놓자

pip 관련

  • python package freeze로 모두 추출하기 (requirements.txt)
    pip freeze > requirements.txt

  • python package freez @annotation 파일 없이 추출하기
    pip list --format=freeze > requirements.txt

  • 의존성도 모두 없애기
    pip list --not-required --format=freeze | cut -d '=' -f 1 > requirements.txt

  • python package 모두 삭제

    • I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv
      pip freeze | xargs pip uninstall -y
    • In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below)
      pip freeze | grep -v "^-e" | xargs pip uninstall -y
    • If you have packages installed directly from github/gitlab, those will have @.
      (ex) django @ git+https://github.com/django.git@)
      You can add cut -d "@" -f1 to get just the package name that is required to uninstall it
      pip freeze | cut -d "@" -f1 | xargs pip uninstall -y
  • [linux] conda / pip cache 파일 삭제 (conda는 밑에서 확인.. 조심할 게 있음)
    $ pip cache purge
    $ conda clean -all


conda 가상환경 관련

  • 아나콘다 버전확인
    conda --version

  • 아나콘다 업데이트
    conda update conda

  • 아나콘다 가상환경 생성
    conda create --name 가상환경이름 사용할패키지 # 예 conda create --name MINSEO python=3.7

  • python version 다운그레이드
    conda install python='원하는버전'

  • 가상환경 리스트 확인
    conda info --env

  • 가상환경 (비)활성화
    (de)activate 가상환경이름

  • 설치된 가상환경 삭제
    conda remove --name 가상환명이름 --all


가상환경 활성화 후 >

  • 패키지 설치
    conda install 패키지명1 패키지명2 패키지명3

  • 설치된 패키지 리스트
    conda list

  • 설치된 패키지 조회
    conda search

  • 설치된 패키지 삭제
    conda remove 패키지명

  • 캐시삭제
    conda clean -all

    ※ 쓸때 조심하자..(with ChatGPT 선생님...)
    'conda clean --all' 명령어는 전체 Conda 환경에 대한 캐시를 삭제합니다. 이 명령어는 패키지 캐시, 플랫폼별 패키지 캐시, 사용하지 않는 패키지와 테일러링된 패키지 등을 삭제하게 됩니다. 특정 가상환경만 대상으로 캐시를 삭제하는 것이 아니라 Conda ㅣㅅ스템 전체의 불필요한 캐시 파일들을 정리해줍니다. 따라서 이 명령어를 실행할 때 주의가 필요합니다.

    environments.yml 파일 실행

    conda 실행 전
    conda env create -f environment.yml

    conda 실행 후
    conda env update --file environment.yml

    Or update a specific environment without activating it:
    conda env update --name envname--file environment.yml

참고

profile
사람을 연구하는 공돌이

0개의 댓글