【自用】linux-python/anaconda环境配置


前言

换了linux服务器,记录一下非root用户的环境部署


一、Anaconda/python

说到python就离不开环境管理。anaconda的windows版本和linux版本的安装其实差别不大,甚至感觉linux安装步骤更少。

1、安装

清华镜像源下载

mkdir pkg
cd pkg
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
sh Anaconda3-5.3.1-Linux-x86_64.sh

# 一路空格
Do you accept the license terms? [yes|no]
[no] >>> 
yes

Anaconda3 will now be installed into this location:
/home/用户/anaconda3   # 默认安装路径

  - Press ENTER to confirm the location    # 按回车确认路径
  - Press CTRL-C to abort the installation    # 按CTRL-C中止安装
  - Or specify a different location below    # 输入指定路径
回车

# 等待安装ing......

installation finished.
Do you wish the installer to initialize Anaconda3   # 是否初始化 Anaconda3
in your /home/用户/.bashrc ? [yes|no]       # 其实就是是否把anaconda3的安装路径写进环境变量
[no] >>> 
yes   

Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]   # 广告,是否安装vscode
>>> 
no   # 肯定no,我又不用。。。

# 如果在添加环境变量那一步不小心打错字(yes-yws/yew/yoe)或者不想自动修改,后面也会有操作提示,按提示手动修改.bashrc文件即可。

安装时第一个yes是同意license,第二个是安装路径,第三个是是否initialize conda,我理解的就是自动修改环境变量,如果不小心打错字(yes-yws/yew/yoe)或者不想自动修改,也可以按提示手动修改.bashrc文件。最后还会问是否需要安装vscode,按需输入yes/no。

手动修改.bashrc的话记得

source .bashrc

最后

conda info   # 检查是否成功安装

2、换源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes

如果出现

3、虚拟环境

# 创建虚拟环境
conda create -n 环境名 python=python版本
# 激活虚拟环境
conda activate 环境名
#退出虚拟环境
conda deactivate

4、可能bug

1.Solving environment: failed

Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/linux-64/repodata.json.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

ConnectionError(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/linux-64/repodata.json.bz2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fcbc4064438>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))"))

conda镜像源的问题,最简单粗暴的方案就是把镜像源的https改成http
如果不行,检查一下是否是域名解析问题

ping www.baidu.com
>>> ping: www.google.com: Temporary failure in name resolution   # 域名解析失败

vim /etc/resolv.conf
# 添加
nameserver 8.8.8.8
nameserver 114.114.114.114

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值