安装Anaconda
推荐更稳定的离线安装,需要下载Anaconda的安装包。
安装包从Anaconda官网或者清华大学镜像站
这里使用Anaconda官网安装包,命令行下载:
wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
bash安装
bash Anaconda3-2023.09-0-Linux-x86_64.sh
看到下列提示直接回车
Welcome to Anaconda3 2023.09-0
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
看到下列许可提示,直接yes就好:
==================================================
End User License Agreement - Anaconda Distribution
==================================================
Copyright 2015-2023, Anaconda, Inc.
All rights reserved under the 3-clause BSD License:
...
Do you accept the license terms? [yes|no]
[no] >>> yes
然后选择安装位置,直接回车默认就好:
Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>>
下面会让选择是否初始化base环境,yes就好,之后也可以配置。
PREFIX=/root/anaconda3
Unpacking payload ...
Installing base environment...
Downloading and Extracting Packages
Downloading and Extracting Packages
Preparing transaction: done
Executing transaction: /
Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
More details are available here: https://intel.github.io/scikit-learn-intelex
For example:
$ conda install scikit-learn-intelex
$ python -m sklearnex my_application.py
done
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
看到如下提示就表示Anaconda3安装成功
no change /root/anaconda3/condabin/conda
no change /root/anaconda3/bin/conda
no change /root/anaconda3/bin/conda-env
no change /root/anaconda3/bin/activate
no change /root/anaconda3/bin/deactivate
no change /root/anaconda3/etc/profile.d/conda.sh
no change /root/anaconda3/etc/fish/conf.d/conda.fish
no change /root/anaconda3/shell/condabin/Conda.psm1
no change /root/anaconda3/shell/condabin/conda-hook.ps1
no change /root/anaconda3/lib/python3.11/site-packages/xontrib/conda.xsh
no change /root/anaconda3/etc/profile.d/conda.csh
modified /root/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
Thank you for installing Anaconda3!
这时需要重新登录终端,检查conda是否正常。
重新登录以后输入
conda env list
如果列出所有环境列表,表示conda一切正常了。
# conda environments:
#
base * /root/anaconda3
安装成功后建议更新一下Anaconda
conda update -y conda
注意:conda更新只能在base环境下进行
查看、创建、切换虚拟环境
使用conda命令,可以方便的创建和切换各版本的python虚拟环境。
查看现有虚拟环境
conda env list
创建虚拟环境
在命令行输入如下命令
conda create --name newEnvName python=3.9
切换虚拟环境
conda activate newEnvName
退出当前虚拟环境
conda deactivate
小妙招
默认情况下,系统会进入base虚拟环境,只要编辑.bashrc文件
vim ~/.bashrc
在最后加入
conda activate newEnvName
即可在下次登录系统后直接进入newEnvName的虚拟环境。
评论列表(2条)