【Python】複製一份 conda 環境的各種方式

使用 .yml 檔案
  • 將當前環境設置輸出為 environment.yml ,再用來創建配置一致的新環境
(base) ~$ conda activate current_env
(current_env) ~$ conda env export > environment.yml
(current_env) ~$ conda deactivate
(base) ~$ conda env create -n new_env -f environment.yml
  • 更新現有環境
(current_env) ~$ conda env update -f environment.yml --prune
  • environment.yml 中對 pip 安裝指令加參數 [ref]
name: your_env
channels:
  - conda-forge
  - defaults
dependencies:
  - ...
  - pip:
    - absl-py==0.15.0
    - git+https://github.com/your_private_package
    - your-package==1.2.3 -f <wheel_source_url>
prefix: /path/of/the/virtual/environment

使用 .txt 檔案
  • 將當前環境設置輸出為 spec_file.txt
(base) ~$ conda activate current_env
(current_env) ~$ conda list --explicit > spec_file.txt
(current_env) ~$ conda deactivate
(base) ~$ conda create -n new_env -f spec_file.txt

更多 conda 指令:

https://docs.conda.io/projects/conda/en/latest/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf

Related Posts

[Python] Selenium Little Known Tips 你可能不知道的 Selenium 技巧

There are some Selenium functions or techniques that I haven’t used before and I don’t know how to write them like this, or they are less intuitive; because they are all fragmented, I will organize them into this article. 有些 Selenium 功能或技巧,沒用過不知道應該要這樣寫,或是比較不直覺的做法;因為都比較零碎,我將它整理到這篇。

[PyTorch] 使用 torch.distributed 在單機多 GPU 上進行分散式訓練

Finetune 語言模型所需要的 GPU memory 比較多,往往會需要我們能夠利用到多顆 GPU 的資源。今天這篇文章會說明 DataParallel 和 DistributedDataParallel + DistributedSampler 兩種進行模型分散式訓練的方式。

發表迴響

%d 位部落客按了讚: