conda环境转移复制和pip包的转移复制以及替换成清华源channels,pip的阿里源

修订 0612 增加conda channel的修改细节(修改的地址)
修订0612 增加了pypi源的官方说明

前言

最近换了PC,需要重新迁移系统。因此研究了相关内容

但是,以下内容仅供参考,因为conda为开源,版本更替很快,无法保证这个流程的可靠性。
当前测试时间:20200519

1,yaml生成

conda导出已有环境:
conda env export > environment.yaml

环境会被保存在 environment.yaml文件中。当我们想再次创建该环境,或根据别人提供的.yaml文件复现环境时,可以:

conda env create -f environment.yaml

就可以复现安装环境。移植过来的环境只是安装了你原来环境里用conda install等命令直接安装的包,你用pip之类装的东西没有移植过来,需要你重新安装。

pip导出安装的库到requirements.txt

pip freeze > requirements.txt

pip导入requirements.txt中列出的库到系统

pip install -r requirements.txt

链接:https://www.jianshu.com/p/b86c17057da8

2,另一台电脑的操作

1、报错
ResolvePackageNotFound:

分析原因:
在这里插入图片描述

是channels中不包含这些package

这就是很迷了!

2、替换成清华源
在这里插入图片描述
channels:

  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

就好了!

希望更新它而不是创建一个新的环境

如果你已经有一个名为myenv的环境,并且你希望更新它而不是创建一个新的环境,你可以使用conda env update -f environment.yaml命令。但是,请注意,这可能会覆盖你当前环境中的某些包和设置,所以请确保你了解这个命令的影响。

3,设置清华源(可选)

官方源:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

由于是开源源,以下内容很难保证可靠性,请访问清华源官方来实现。


可以选择国外的

国内的可能会快一点

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/
# 以上两条是Anaconda官方库的镜像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# 以上是Anaconda第三方库 Conda Forge的镜像

# for linux
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
以上两条是Pytorch的Anaconda第三方镜像

conda config --set show_channel_urls yes

添加完成后可以使用conda info命令查看是否添加成功.

conda config --set show_channel_urls yes

设置为yes,在使用conda install安装Python包时,会显示这个包来自于哪个源

补充 官网介绍

Anaconda 是一个用于科学计算的 Python 发行版,支持 Linux, Mac, Windows, 包含了众多流行的科学计算、数据分析的 Python 包。

Anaconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载。

TUNA 还提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等,查看完整列表)的镜像,各系统都可以通过修改用户目录下的 .condarc 文件。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。

注:由于更新过快难以同步,我们不同步pytorch-nightly, pytorch-nightly-cpu, ignite-nightly这三个包。

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
即可添加 Anaconda Python 免费仓库。

运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

运行 conda create -n myenv numpy 测试一下吧。

3.1 修改的文件位置

此时,目录 C:\Users<你的用户名> 下就会生成配置文件.condarc
在这里插入图片描述
通过命令 conda info 查看当前配置信息,内容如下,即修改成功,关注 channel URLs 字段内容

https://www.jianshu.com/p/042fd657e2d4

4,问题:CondaEnvException: Pip failed

更换pip的阿里源
pip国内的一些镜像

清华官方:https://mirror.tuna.tsinghua.edu.cn/help/pypi/

豆瓣

https://pypi.doubanio.com/simple/

阿里云

https://mirrors.aliyun.com/pypi/simple/

清华大学

https://pypi.tuna.tsinghua.edu.cn/simple/
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/

临时使用

pip install some-package -i https://mirrors.aliyun.com/pypi/simple/

该网站指定为可信任就行了~

pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

设为默认

升级 pip 到最新的版本后进行配置:

pip install pip -U
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

在https://blog.csdn.net/yuzaipiaofei/article/details/80891108中采用了建立pip.ini的方式

永久修改:
linux:
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host= pypi.tuna.tsinghua.edu.cn

windows:

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,在pip 目录下新建文件pip.ini,内容如下

或者按照网友的建议:win+R 打开用户目录%HOMEPATH%,在此目录下创建 pip 文件夹,在 pip 目录下创建 pip.ini 文件, 内容如下

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

5,问题:UnsatisfiableError:

UnsatisfiableError: The following specifications were found to be incompatible with each other:

我换成了国外的源就没报错?

  • anaconda
  • anaconda-fusion
  • defaults
  • conda-forge
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hali_Botebie

文中错误请不吝指正!!!!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值