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

相关推荐
莓有烦恼吖1 小时前
Vibe Coding 的一些思考
python
小白学大数据1 小时前
超简单:用 Python 让 Excel 飞起来:用 openpyxl 把重复报表整理交给脚本
开发语言·数据库·python·excel
爱丶不疚1 小时前
写给前端工程师的现代 Python 工程化最佳实践:从 pnpm 到 uv,从 CommonJS 到 src-layout
javascript·python·typescript
2601_962297251 小时前
C# vs Java vs Python:YOLO工业部署性能对比实战
java·python·c·工业视觉·性能对比
CTA终结者2 小时前
示例、拆解和练习,要连成一条量化补课线
人工智能·python
lolijiaqi152 小时前
一线观察:长期体验后发现的医疗器械 CDMO 底层现象
大数据·python
spencer_tseng2 小时前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache
梦想不只是梦与想3 小时前
Python Web 框架:FastAPI
python·fastapi·web框架
玩大数据的龙威3 小时前
农经权二轮延包—全面取代人工公示图生成
python·arcgis
IT_Octopus3 小时前
JSON 日志里的 `{“$ref“:“$.xxx“}`:从 fastjson 兼容包到原生 fastjson2 的迁移实录
开发语言·python·json