Anaconda体验,这玩意儿是真的香啊,强力推荐!
- 共 947 次检阅

之前对conda虚拟环境不了解,觉得可能颇有难度,一直都没咋去研究过,在群里认识一个浙江的网友,需要搭建一个LatinChat的知识库,起初是centos7.X(深度学习强烈建议ubuntu-server系统,个人拙见)的系统,Tesla T4的显卡驱动打不上(怀疑卡有毛病),折腾许久就等着换了新的机器,新的机器到了以后上了python3.11.7的环境,安装latinchat的环境的时候出了问题(安装python3.11.7的时候覆盖了原本ubuntu18.X的默认版本python3.6.X),各种底层库报错缺胳膊少腿,前前后后折腾了很久,后面发现大多深度学习都使用虚拟环境,环境隔离,第一次索性就抱着试试的态度安装run一下,后面发现一路pip install -r requirements.txt安装一把梭是真香(小白初体验)!

 

从Anaconda获取最新版的安装包:

https://www.anaconda.com/download/success

找到下载liunx的包以后,服务器使用wget下载到服务器任意目录(安装后可删除,一个sh文件)

wget https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh

安装后给予权限:

chmod 755 Anaconda3-2024.02-1-Linux-x86_64.sh
./Anaconda3-2024.02-1-Linux-x86_64.sh

执行过后会有很长的信息要阅读,阅读完了以后输入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] >>> 

安装完成以后会在root目录下,不建议移动到其它目录,(未知可否,反正我移动过后跑不了),安装完成后,会询问你是否进行初始化,输入yes回车即可

You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
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!
root@iZj6c7kmpd1guj0yk4qdm4Z:/home# 

完成初始化完成以后,使用ln -s 软连接conda一下,以后可直接使用conda创建切换虚拟环境

ln -s /root/anaconda3/bin/conda  /usr/bin/conda

完成以后创建一个虚拟环境测试一下

conda create -n test python=3.11.7
# 提示是否安装一些组件的时候直接Y同意就好了

# 切换到虚拟环境
conda activate test

# 会出错
CondaError: Run 'conda init' before 'conda activate'

解决方法:

运行 conda init。这个命令会初始化你的 shell 环境,让它包含 Conda,并默认激活基础 Conda 环境。

conda init

 

运行 conda init 后,你可能需要重新启动终端或者加载你的 shell 配置文件以应用更改。通常可以通过以下命令之一来完成:

source ~/.bashrc
source ~/.bash_profile

这取决于你使用的是哪种 shell(bash、zsh 等),以及哪个配置文件适合你的 shell。
一旦 Conda 初始化完成,你就可以再次激活“test”环境:

conda activate test

完成安装,按需使用即可

分享到:

这篇文章还没有评论

发表评论