Anaconda Distribution 和 Miniconda的选择
– 如果不确定安装哪个包的话,建议直接安装Anaconda Distribution版本:Anaconda Distribution包含了250多个标准数据科学和机器学习的包,初学者可以给予已经提供的包快速上手开发。
– 习惯于图形界面,对命令行不熟悉: 建议直接安装Anaconda Distribution版本,Anaconda Distribution版本包含了Anaconda Navigator,它是conda的一个桌面应用,基于此应用,你可以通过图形化的界面创建环境(environment),安装包,加载类似Jupyter Notebooks和Spyder等开发应用。
– 如果不确定将来使用哪些包,或者不想下载一个700M的文件:建议安装Miniconda,它是conda的一个最小化安装,包含了必须要的conda,python和几个必须要的包。
– 如果只使用命令行,不需要图形化界面:Anaconda Distribution和Miniconda任选一个都行,两个都包含了conda、python,支持命令行,支持环境管理(environment manager)。
Linux下安装Anaconda Distribution
– Anaconda Navigator依赖QT,安装Anaconda Distribution之前确保已安装QT相关依赖,不同架构系统可参考:https://docs.anaconda.com/free/anaconda/install/linux/
– 不同架构,对应的安装包不同,最新的版本可以在Anaconda仓库查询,并下载相应的安装包:repo.anaconda.com/archive/
– 修改安装包为可读写模式:chmod 755 Anaconda3-*.sh
– 执行安装:bash Anaconda3-*.sh
– 按照提示完成安装过程;
– 通过如下命令配置是否在启动时激活base环境
# The base environment is activated by default
conda config --set auto_activate_base True
# The base environment is not activated by default
conda config --set auto_activate_base False
# The above commands only work if conda init has been run first
# conda init is available in conda versions 4.6.12 and later
Linux下安装Miniconda
– 不同python版本对应的Miniconda地址如下:https://docs.anaconda.com/free/miniconda/miniconda-other-installer-links/
– 下载对应版本的Miniconda,使用命令bash filename安装;
– 使用conda list查询已安装的包;
使用conda创建环境
– 通过命令conda create -n envname创建环境,样例如下:
zhangzhijun@ZhangZhijun-MacBook ~ % conda create -n pytorchBeginner
Channels:
-defaults
Platform: osx-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environmentlocation:/usr/local/Caskroom/miniconda/base/envs/pytorchBeginner
Proceed ([y]/n)?
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pytorchBeginner
#
# To deactivate an active environment, use
#
# $ conda deactivate
– 激活环境
conda activate pytorchBeginner
FAQ
Q1:环境激活失败
zhangzhijun@ZhangZhijun-MacBook ~ % conda activate pytorchBeginner
CondaError: Run 'conda init' before 'conda activate'
zhangzhijun@ZhangZhijun-MacBook ~ % conda init
no change /usr/local/Caskroom/miniconda/base/condabin/conda
no change /usr/local/Caskroom/miniconda/base/bin/conda
no change /usr/local/Caskroom/miniconda/base/bin/conda-env
no change /usr/local/Caskroom/miniconda/base/bin/activate
no change /usr/local/Caskroom/miniconda/base/bin/deactivate
no change /usr/local/Caskroom/miniconda/base/etc/profile.d/conda.sh
no change /usr/local/Caskroom/miniconda/base/etc/fish/conf.d/conda.fish
no change /usr/local/Caskroom/miniconda/base/shell/condabin/Conda.psm1
no change /usr/local/Caskroom/miniconda/base/shell/condabin/conda-hook.ps1
no change /usr/local/Caskroom/miniconda/base/lib/python3.12/site-packages/xontrib/conda.xsh
no change /usr/local/Caskroom/miniconda/base/etc/profile.d/conda.csh
no change /Users/zhangzhijun/.bash_profile
No action taken.
zhangzhijun@ZhangZhijun-MacBook ~ % conda activate pytorchBeginner
CondaError: Run 'conda init' before 'conda activate'
关闭终端重新打开仍然无效,可执行如下命令:
zhangzhijun@ZhangZhijun-MacBook~%source~/.bash_profile
zhangzhijun@ZhangZhijun-MacBook ~ % conda activate pytorchBeginner
(pytorchBeginner) zhangzhijun@ZhangZhijun-MacBook ~ %
参考资料:
[1] conda 官网:https://docs.anaconda.com/free/