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 版本了,是不是非常方便

相关推荐
大貔貅喝啤酒3 小时前
Python Requests库教程
自动化测试·python·requests库
copyer_xyf4 小时前
LangChain 调用 LLM
后端·python·agent
copyer_xyf4 小时前
Prompt 组织管理
后端·python·agent
shimly1234565 小时前
python3 uvicorn 是啥?
python
CTA量化套保5 小时前
期货量化程序 time.sleep 卡死:天勤单线程与 deadline 替代
python·区块链
GIS数据转换器6 小时前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
贤哥哥yyds6 小时前
GBK转UTF\-8编码自动转换工具 使用文档
python
数量技术宅6 小时前
2026量化前沿:从Reddit热帖到Python实战,如何用赫斯特指数(Hurst)狙击虚假突破?
开发语言·python
华如锦6 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai
戴西软件7 小时前
戴西 DLM 许可授权管理系统:破解无网络环境下工业软件授权难题,助力制造企业降本增效
网络·人工智能·python·深度学习·程序人生·算法·制造