当前位置:   article > 正文

Linux服务器Anaconda环境配置与用户管理_anaconda linux

anaconda linux

 一、Linux服务器安装Anaconda

1、下载Anaconda

①进入官网传送门,下载对应的版本(Linux),然后打开terminal,将安装包上传到服务器

②当然,也可以直接在服务器通过wget指令下载:

  1. # 下载命令
  2. wget https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh

 一般直接放在自己文件夹下即可:/home/jst/Anaconda3-5.3.0-Linux-x86_64.sh

2、安装Anaconda

进入​​Anaconda3-5.3.0-Linux-x86_64.sh所在目录,执行以下命令:

  1. # 赋权命令:
  2. chmod +x Anaconda3-5.3.0-Linux-x86_64.sh
  3. # 安装命令:
  4. ./Anaconda3-5.3.0-Linux-x86_64.sh

安装过程一直按回车(或者按一次空格),最后输入yes同意用户许可证:

按照终端窗口中的提示,输入yes,将Anaconda的bin目录添加到系统的PATH环境变量中。这样可以方便地在终端中运行Anaconda的命令。如果不小心跳过了此步骤,参考博客[传送门]手动进行环境变量配置。是否安装VSCode,这个看个人需求,我是输入no的:

至此安装完成,重启之后就能使用啦!

3、conda 管理虚拟环境

  1. # 1. 查看conda版本
  2. conda --version
  3. # 2. 创建指定python版本的环境
  4. conda create --name jst python=3.8
  5. # 3. 激活环境
  6. conda activate jst
  7. # 4. 退出环境
  8. conda deactivate
  9. # 5. 查看所有已创建的conda虚拟环境
  10. conda info -e
  11. # 6. 克隆同设备下的conda虚拟环境(旧:A 新:B)
  12. conda create -n B --clone A

4、安装Python软件包

一般来说,用pip install就行了,至于conda install与其有什么区别,详见博客[传送门]

  1. # 安装项目requirements.txt文件依赖:
  2. pip install -r requirements.txt
  3. # 生成requirements.txt文件:
  4. pip freeze > requirements.txt

 注意!安装torch和torchvision时,两者之间存在依赖关系,版本需要对应起来,参考博客[传送门]

5、创建虚拟环境失败的解决方法

如果在创建虚拟环境时出现以下报错:

  1. Solving environment: failed
  2. CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/free/noarch/repodata.json.bz2>
  3. Elapsed: -
  4. An HTTP error occurred when trying to retrieve this URL.
  5. HTTP errors are often intermittent, and a simple retry will get you on your way.
  6. If your current network has https://www.anaconda.com blocked, please file
  7. a support request with your network engineering team.
  8. SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/free/noarch/repodata.json.bz2 (Caused by SSLError(SSLError("bad handshake: Error([(\'SSL routines\', \'ssl3_get_server_certificate\', \'certificate verify failed\')])")))'))

 解决方法:关闭SSL认证。输入以下指令即可:

conda config --set ssl_verify false

6、在服务器安装需要翻墙的库 

例如安装CLIP的时候出现以下报错:

  1. Obtaining clip from git+https://github.com/openai/CLIP.git@main#egg=clip (from -r requirements.txt (line 25))
  2. Cloning https://github.com/openai/CLIP.git (to revision main) to ./src/clip
  3. Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /home/jst/code/instruct-pix2pix-main/src/clip
  4. fatal: unable to access 'https://github.com/openai/CLIP.git/': Failed to connect to github.com port 443 after 131058 ms: Connection timed out
  5. error: subprocess-exited-with-error
  6. × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /home/jst/code/instruct-pix2pix-main/src/clip did not run successfully.
  7. exit code: 128
  8. ╰─> See above for output.
  9. note: This error originates from a subprocess, and is likely not a problem with pip.
  10. error: subprocess-exited-with-error
  11. × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /home/jst/code/instruct-pix2pix-main/src/clip did not run successfully.
  12. exit code: 128
  13. ╰─> See above for output.
  14. note: This error originates from a subprocess, and is likely not a problem with pip.

解决方法(当然,切换成清华源也可以):

进入CLIP的GitHub网址,先将CLIP下载到本地,即点击下图中的Download ZIP,将该压缩包上传到服务器后进行解压,得到文件夹CLIP-main。

打开Anaconda,激活虚拟环境,在虚拟环境下进入文件夹CLIP-main,然后再输入以下指令进行clip包的安装:

pip install .

或者,直接将原来的指令拆解成下列指令,在服务器终端执行:

  1. git clone https://github.com/openai/CLIP.git
  2. cd CLIP
  3. pip install .

 7、Huggingface下载连接不稳定

问题说明

在使用到huggingface时,下载连接不稳定导致ConnectError

解决方法

使用镜像网站链接解决稳定性问题,可使用以下方法改变huggingface网址,在命令行中设置环境变量:

HF_ENDPOINT=https://hf-mirror.com python xxx.py

二、Linux服务器的账号管理

1、创建账号

1. 进入root模式(超级用户):

sudo su

2.任意路径执行命令:

  1. # 添加用户jst
  2. adduser jst

3.设置登录密码:

  1. # jst为前面注册的用户名(注意这里输入密码不回显)
  2. passwd jst
  3. # 后续若要更改密码,登录jst用户后,输入以下指令即可
  4. passwd

 创建的新用户会在home目录下生成一个该用户名命名的文件夹。

2、删除账号

  1. # 切换到root
  2. sudo su
  3. # jst为已注册的用户名
  4. userdel -r jst

3、将用户添加到sudo组

  1. # 切换到root
  2. sudo su
  3. # jst是待授予权限的用户名,重启后生效
  4. usermod -aG sudo jst

三、Linux服务器的常用命令

1、服务器间传输文件

将服务器1的文件夹/home/jst/1全部传输至服务器2的/home/jst/code/2/路径下:

  1. scp -P 22 -r /home/jst/1 jst@192.168.1.103:/home/jst/code/2/
  2. # 注意,-P要改成服务器192.168.1.103的端口号,此处为22

常用可选参数:

  • -B 使用批处理模式(传输过程中不询问传输口令或短语)
  • -C 允许压缩。(将-C标志传递给ssh,从而打开压缩功能)
  • -p 保留原文件的修改时间,访问时间和访问权限。
  • -r 递归复制整个目录。
  • -P port 注意是大写的P, port是指定数据传输用到的端口号

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/979906
推荐阅读
相关标签
  

闽ICP备14008679号