Ubuntu 安装和配置 Anaconda3
ubuntu 安装和配置 Anaconda3
ubuntu18.04.5 LTS, anaconda3-2021.11-Linux-x86_64.sh
下载Anaconda
-
选择下载之后,将文件保存到Document文件夹里
下载后的文件名为Anaconda3-2021.11-Linux-x84_64.sh
安装
-
运行安装
sh ~/Document/Anaconda3-2021.11-Linux-x84_64.sh
-
按住回车跳过slice阅读
-
输入yes确定安装
-
如果想安装到其他位置,则输入想安装的位置,否则直接回车
-
等待几分钟安装完成,输入yes,回车(若输入no,则需要配置环境变量(见配置部分),否则不能使用conda命令)
配置
1. 环境变量配置
-
运行安装
sh ~/Document/Anaconda3-2021.11-Linux-x84_64.sh
-
按住回车跳过slice阅读
-
输入yes确定安装
-
如果想安装到其他位置,则输入想安装的位置,否则直接回车
-
等待几分钟安装完成,输入yes,回车(若输入no,则需要配置环境变量(见配置部分),否则不能使用conda命令)
配置
1. 环境变量配置
-
在用户根目录下 修改
.bash_profile
文件可以使用ubuntu系统的自带编辑软件,也可以使用vi或vim编辑,选择下面任意一行命令输入,编辑文件即可
gedit ~/.bashrc vi ~/.bashrc vim ~/.bashrc
-
添加内容
在
.bashrc
文件最后追加下面的内容# Config Anaconda export PATH="/home/yfb/apps/anaconda/bin:$PATH"
PATH 中anaconda的路径根据实际安装位置做修改。
保存完文件后,在终端中输入
source ~/.bash_proflie
,更新环境变量 -
验证
输入以下命令,没有报错则安装成功
conda -V conda env lsit
2. 镜像源配置
2.1 conda 配置清华源
-
按
ctrl+alt+T
打开终端,输入以下命令conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ conda config --set show_channel_urls yes
前三个命令添加源,最后一个命令允许conda search时显示channel地址
-
查看添加的源
conda config --show channels
-
若添加错误,可删除源 。下边为例:
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
2.2 pip镜像源设置
-
临时设置
pip install 时使用-i参数添加源地址,例如
pip install numpy==1.15.4 -i https://mirrors.aliyun.com/pypi/simple/
-
永久设置
讲pip镜像源设置写入到文件~/.pip/pip.conf
cd ~ mkdir .pip cd .pip echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple" > pip.conf cat pip.conf
cat命令能看到pip.conf的内容
关于环境变量配置
在ubuntu系统中设置环境变量和设置一些配置,相关的文件有 /etc/profile
, /etc/bashrc
, ~/.bash_profile
, ~/.bashrc
等,这些文件的执行时间不同,先后顺序不同,具体参考一下文章:linux 下/etc/profile、/etc/bashrc、/.bash_profile、/.bashrc 文件的区别
发现还是不要使用 ~/.bash_profile
文件进行配置了,很可能会碰到重启系统或重启终端后发现设置不起作用的情况(仅是个人总结,如果有意见或建议,欢迎评论)。