【2022】Centos7.4安装anaconda3(anaconda2021.11)

【2022】Centos7.4安装anaconda3(anaconda2021.11),第1张

【2022】Centos7.4安装anaconda3(anaconda2021.11) 一、下载anaconda

如果你要将anaconda共享给同一主机的其他用户使用,不要用root用户安装anaconda,其他用户无法共享root用户的anaconda。我的服务器就我一个人使用,我还是选择root用户安装。

1.1 进入清华镜像源下载anaconda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
    可能提示:
错误: 无法验证 mirrors.tuna.tsinghua.edu.cn 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
  颁发的证书已经过期。

修改命令

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh --no-check-certificate

    提示没有wget

    安装即可

yum -y install wget
二、安装anaconda 2.1 进入下载目录执行文件
bash Anaconda3-2021.11-Linux-x86_64.sh

提示Do you accept the license terms? [yes|no],输入yes

Do you accept the license terms? [yes|no]
[no] >>> 
Please answer 'yes' or 'no':
>>> yes
2.2 是否要修改安装路径,如果不修改就直接按回车(Enter)确认
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] >>> 

如果需要修改,就输入要安装到的绝对路径

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] >>> /opt/anaconda3

    提示找不到bunzip2

    Anaconda3-2021.11-Linux-x86_64.sh: line 353: bunzip2: command not found
    tar: This does not look like a tar archive
    tar: Exiting with failure status due to previous errors
    

    安装bzip2即可:

    yum install -y bzip2
    

    解决完bzip2后,重复前面的步骤安装anaconda3

2.3 是否需要进行conda的初始化

若选择yes,会在/root/.bashrc目录中自动添加环境变量,会使得开机自动启动base环境。

如果选择了no,需要自行配置conda命令环境变量。这也是为什么出现-bash: conda: 未找到命令的原因

2.4 安装成功
Thank you for installing Anaconda3!

===========================================================================

Working with Python and Jupyter notebooks is a breeze with PyCharm Pro,
designed to be used with Anaconda. Download now and have the best data
tools at your fingertips.

PyCharm Pro for Anaconda is available at: https://www.anaconda.com/pycharm
三、配置anaconda 3.1 conda初始化选择yes

这时候conda命令是可以直接使用的,输入几条命令测试一下

source activate # 进入conda环境 出现(base)则说明安装成功
conda deactivate # 退出conda环境
3.2 conda 初始化选择no

这时候conda命令无法使用,需要我们自行配置环境变量,方法也很简单

3.2.1 打开profile文件

vim /etc/profile

3.2.2 在文件的最后加入如下内容(我使用的是默认安装路径,如果你修改了安装路径,就需要根据自己 的安装路径修改path的内容)

vim跳转到文件头和文件末尾的命令:

gg : 跳转到文件头

Shift+g : 跳转到文件末尾

行数+gg : 跳转到指定行,例跳转到123行:123gg

shift+gg跳转到最后一行,输入o就可以快速添加新的一行,然后添加。

PATH=$PATH:/root/anaconda3/bin
export PATH

3.2.3 退出并保存

按下 Esc ,然后输入:wq,就退出vim,并保存了文件。

3.2.4 刷新环境变量

source /etc/profile
echo $PATH

3.2.5 测试anaconda

conda activate # 进入conda环境 出现(base)则说明安装成功
conda deactivate # 退出conda环境

如果输入conda activate,提示提示“CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.”错误

那么应该使用source activate

具体原因可以参考:linux下的source命令

四、使用anaconda创建环境

anaconda创建环境的命令为

conda activate -n 环境名 python==python版本

创建一个名为spider,python版本为3.8的环境

conda create -n spider python==3.8

提示Proceed ([y]/n)?,输入y。

激活spider的环境,出现(spider)即成功。

conda activate 环境名

conda activate spider

在新的环境中安装包

pip install 包名

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5720509.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存