conda入门笔记

conda 使用笔记

1. 什么是conda

conda 是一个开源的软件包管理系统和环境管理系统,他可以在windows、macOS、linux环境下运行。

Conda是一个开源的软件包管理系统和环境管理系统,主要用于在不同的操作系统上安装、运行和管理多个软件包和环境。下面是一些使用Conda的原因:

  1. 管理软件包:Conda可以方便地安装、更新和删除各种软件包,这些软件包可以是Python包,也可以是其他语言的包。Conda提供了一个广泛的软件包库,其中包含了许多常用的科学计算、数据分析和机器学习工具。

  2. 管理环境:Conda可以创建和管理独立的环境,每个环境可以有自己独立的软件包集合和配置。这样可以避免不同软件包之间的冲突,并且可以轻松地在不同的项目之间切换环境。

  3. 跨平台支持:Conda可以在多个操作系统上运行,包括Windows、Mac和Linux。这意味着您可以在不同的操作系统上使用相同的软件包和环境配置,而不需要重新安装和配置。

  4. 管理依赖关系:Conda可以解决软件包之间的依赖关系,确保所需的软件包和版本可以正确安装和运行。这对于复杂的项目和库的管理非常重要。

  5. 安装便捷:Conda提供了一个简单的命令行接口,使得安装、更新和删除软件包非常方便。此外,Conda还提供了一个图形用户界面(Anaconda Navigator),使得非技术人员也能够轻松地使用Conda进行软件包和环境管理。

总而言之,Conda提供了一个强大而灵活的方式来管理软件包和环境,使得开发人员、数据科学家和研究人员能够更轻松地构建和管理复杂的软件项目和数据分析环境。

5.1 install conda

安装教程官网地址:

https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html#

5.1.1 MAC 环境安装教程
https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html#

5.1.2 Windows 环境安装教程
https://docs.anaconda.com/miniconda/
历史版本下载地址
https://docs.anaconda.com/miniconda/miniconda-other-installer-links/

5.2 conda 常用指令

5.2.1 虚拟环境常用操作指令

  # 查看conda信息
  
  $ conda info
  
  # 创建虚拟环境 -n 虚拟环境名称
  $ conda create -n AIGC python=3.9.18
  
  # 激活虚拟环境AIGC
  $ conda activate AIGC
  
  # 终止虚拟环境
  $ conda deactivate AIGC
  
  # 查看虚拟环境列表
  $ conda env list
  
  # 删除虚拟环境
  $ conda remove -n AIGC --all
  
  # 安装包 -n 指定虚拟环境
  $ conda install simplejson -n AIGC
  
  # 查看安装包list
  $ conda list -n AIGC
  
 
  
  # 添加镜像源(清华)
  conda config --add 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/free/
  conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  
  # 删除镜像源
  conda config --remove channels $镜像地址
  

6. conda CondaHTTPError: HTTP 000 CONNECTION 问题跟踪

6.1 遇到问题
- Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fd39f2aae20>, 'Connection to repo.anaconda.com timed out. (connect timeout=9.15)')': /pkgs/r/noarch/repodata.json.zst

failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/osx-64/repodata.json>
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://repo.anaconda.com blocked, please file
a support request with your network engineering team.

'https//repo.anaconda.com/pkgs/main/osx-64'

6.2 问题原因分析
从提示中我们不难看出,是因为我们的网络环境连接不到conda的官网镜像源。

6.3 解决方法
6.3.1 切换网路

这个需要你能连接到外部网络,可能比较费事,这里我就不说了

6.3.2 添加国内镜像源
  1. 添加镜像源-指令-清华
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

  1. 查看conda信息,确认仓库添加成功
conda info

在这里插入图片描述

可以看到我们的镜像已经加进去,conda官网的地址还在,再次创建虚拟空间依然不行

conda create -n test python=3.9.18

在这里插入图片描述

  1. 看来我们要删除官网的镜像地址

# 找到conda的配置文件
$ vim ~/.condarc

在这里插入图片描述

文件内容

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

删除 channels defaults 配置即可,删除后的配置信息如下

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true

再次创建空间

在这里插入图片描述
在这里插入图片描述

ok,到此问题就解决了

哎,conda的问题解决了,pip的镜像源有同样的问题,也需要切换到国内的镜像源,同一个世界,确实不一个网络。。。切换指令如下:

$ pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 阿里云 http://mirrors.aliyun.com/pypi/simple/
# 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
# 豆瓣(douban) http://pypi.douban.com/simple/
# 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
# 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值