【自用】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