Mamba 虛擬環境常用指令整理

Table of Contents

安裝 Mamba

conda install -n base -c conda-forge mamba

創建虛擬環境

創建一般虛擬環境

mamba create -n my_env python=3.9
  • my_env:虛擬環境名稱
  • python=3.9:指定 Python 版本

在當前資料夾建構虛擬環境

mamba create -p ./env python=3.9
  • ./env:虛擬環境將被建立在當前資料夾內
  • python=3.9:指定 Python 版本

啟動虛擬環境

mamba activate my_env

或啟動當前資料夾中的虛擬環境:

mamba activate ./env

停用虛擬環境

mamba deactivate

列出所有虛擬環境

mamba env list

mamba info --envs

刪除虛擬環境

mamba remove -n --all my_env
mamba env remove -n my_env

或刪除當前資料夾中的虛擬環境:

mamba remove -p ./env --all

安裝套件

mamba install numpy pandas
  • 可同時安裝多個套件

升級套件

mamba update numpy

或更新所有套件:

mamba update --all

刪除套件

mamba remove numpy

查詢已安裝的套件

mamba list

或查詢特定套件:

mamba list numpy

匯出環境 (建立 .yml 設定檔)

mamba env export > environment.yml

.yml 檔案建立環境

mamba env create -f environment.yml

複製環境

mamba create -n new_env --clone my_env
  • new_env:新環境名稱
  • my_env:要複製的環境名稱

清理未使用的套件與快取

mamba clean --all

移除 Mamba (如需回到 Conda)

conda install conda

Disclaimer: All reference materials on this website are sourced from the internet and are intended for learning purposes only. If you believe any content infringes upon your rights, please contact me at csnote.cc@gmail.com, and I will remove the relevant content promptly.


Feedback Welcome: If you notice any errors or areas for improvement in the articles, I warmly welcome your feedback and corrections. Your input will help this blog provide better learning resources. This is an ongoing process of learning and improvement, and your suggestions are valuable to me. You can reach me at csnote.cc@gmail.com.