Conda安装&使用

简介

Conda 是一个主打解决 Python/R 安装、版本冲突与环境隔离问题的包管理器,如果你的操作系统手动安装 Python 非常困难和麻烦,可以考虑使用它来安装。

本文介绍如何在 CentOS 上安装 Conda,以及使用它来安装一个自定义版本的 Python。

安装

敲下面的命令,下载安装脚本

shell 复制代码
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

如果没有 wget 程序,可以敲下面的命令安装一个

shell 复制代码
yum install -y wget

如果有网络问题,可以像我一样,将地址拷贝到浏览器/迅雷上下载

下载下来后,上传到服务器,敲下面的命令执行

shell 复制代码
bash Miniconda3-latest-Linux-x86_64.sh

我这个 GLIBC 版本不支持安装最新的

换下面这个版本

shell 复制代码
wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh

安装

shell 复制代码
bash Miniconda3-py39_4.10.3-Linux-x86_64.sh

如下

是否需要初始化,选择 yes

安装完,敲下面的命令验证

shell 复制代码
source ~/.bashrc
conda --version

如下,出现版本号说明安装完成

再配置一些国内的镜像,方便后面下载库

shell 复制代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/
conda config --set show_channel_urls yes

安装完 Conda 自带就有了 Python 环境,可以敲下面的命令查看

shell 复制代码
python3 -V
pip -V

如下

使用

如果想要其他 Python 版本的环境,可以敲下面的命令安装切换

如下,创建一个 Python-3.11.15 版本的环境,其中 py-3.11.15 是环境名称

shell 复制代码
conda create -n py-3.11.15 python=3.11.15

如下,创建好了

如果失败了,敲下面的命令,重新设置一下镜像源

powershell 复制代码
# 清空旧配置
conda config --remove-key channels
# 添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# 显示包的来源
conda config --set show_channel_urls yes

敲下面的命令激活该环境

shell 复制代码
conda activate py-3.11.15

如下,激活后就是前面设置的 Python 版本了,是不是非常方便

相关推荐
用户8356290780512 天前
Python 实现 PDF 文件加密与解密方法
后端·python
用户8356290780512 天前
使用 Python 冻结与拆分 Excel 窗格教程
后端·python
你好潘先生2 天前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
Agent_大师2 天前
WebSocket 行情重连成功,K线缺口不会自动消失
python
荣码2 天前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
copyer_xyf2 天前
FastAPI 如何连接 MySQL
后端·python
apocelipes3 天前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
用户8356290780513 天前
使用 Python 在 PDF 中创建与管理书签
后端·python
MeixianAgent3 天前
Python 回测数据入口怎么验?历史 K 线入库前先做 5 个检查
后端·python
咕白m6253 天前
用 Python 实现一键批量查找与替换 Excel 数据
后端·python