背景
今天在AutoDL上新开了一台机器,准备装环境,执行命令
conda create -n sparseo*** python=3.8 -y
后显示:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
以下几个尝试都不太行:
(这个不行)conda clean -a 来清除缓存
(这个不行)将镜像源地址从 https 改为 http
(这个还没尝试,升级应该是最好的办法了)升级conda
升级conda 这个贴子里给出了几种可能得原因:
可能出错的原因
Anaconda中conda在安装某个包后出现"Solving environment: \一直转 卡住不动"的问题可能由以下几个原因引起:
- 网络连接问题:Conda需要从互联网上下载包和环境配置,如果网络连接不稳定,可能会导致升级或解决环境时卡住
- Conda缓存问题:Conda使用缓存存储已下载的包和环境配置,缓存中的数据可能会导致升级或解决环境时出现问题
- Conda版本过旧:使用的Conda版本较旧可能会遇到一些问题,更新Conda到最新版本可能会解决这个问题
- 依赖关系问题:Conda在尝试解决依赖关系时出现了问题,导致无法正常进行更新
- 镜像源问题:使用不同的镜像源可能会加速Conda的升级或解决环境过程
- 性能问题:包管理器的性能问题也可能导致Conda在更新时卡住
(已经换过了)conda 换清华源
但是如图所示,AutoDL已经是清华源了
补充:conda 换清华源
把下面的代码一行一行复制到anaconda prompt里执行,就能完成换源!
conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/r/ conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/cloud/pytorch/ conda config --set show_channel_urls yes conda clean -a -y # 为了确保配置生效,可以清理一下旧的缓存(可选,但推荐)执行“conda info”命令可以查看现在的channels,觉得有问题,可以使用命令:
conda config --remove channels "http://mirrors.tuna.tsinghua.edu.***/anaconda/cloud/pytorch/linux-64"移出多余的,比如这里移出的是http开头的,这不够安全
补充:pip永久换清华源
# 清华源 pip config set global.index-url https://pypi.tuna.tsinghua.edu.***/simple # 阿里云 pip config set global.index-url https://mirrors.aliyun.***/pypi/simple
尝试:重装conda
之前AutoDL给的的conda版本是4.14,于是选择重新装个镜像:
这不影响数据盘,然后重进终端,这次conda版本降低到了4.10.3
然后补充了一个AutoDL没有的清华源
(base) root@autodl-container-e70d438c6c-3e976378:~# pip config set global.index-url https://pypi.tuna.tsinghua.edu.***/simple
Writing to /root/.config/pip/pip.conf
(base) root@autodl-container-e70d438c6c-3e976378:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/r/
(base) root@autodl-container-e70d438c6c-3e976378:~# conda config --set show_channel_urls yes
(base) root@autodl-container-e70d438c6c-3e976378:~#
看看这次效果:
base) root@autodl-container-e70d438c6c-3e976378:~# conda create -n sparseo*** python=3.8 -y
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.10.3
latest version: 25.5.1
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /root/miniconda3/envs/sparseo***
added / updated specs:
- python=3.8
The following packages will be downloaded:
package | build
---------------------------|-----------------
_libg***_mutex-0.1 | main 3 KB https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/main
_openmp_mutex-5.1 | 1_gnu 21 KB https://mirrors.tuna.tsinghua.edu.***/anaconda/pkgs/main
...
xorg-libxau-1.0.12 | 13 KB | ############################################################################################################## | 100%
setuptools-75.1.0 | 1.7 MB | ############################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate sparseo***
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) root@autodl-container-e70d438c6c-3e976378:~#
成功装上了,即使还是出现了current_repodata.json搞不定(不稳定)的问题,但这次conda自己转到了repodata.json进行尝试,没有完全成功解决
在进一步装pytorch时遇到了问题:“Solving environment: failed with initial frozen solve. Retrying with flexible solve.”
解决方案:python其实已经装好了!conda新建环境,pip装依赖包即可
AutoDL在创建实例时,咱们选择的镜像已经把python装好了
pip无法直接安装Python本身,只能安装Python的包(如numpy、torch等)
conda用来管理Python版本,比如创建/切换不同的Python版本环境
- conda list 会显示当前环境中通过conda或pip安装的包
- 但Python本身是环境的基础,它不是以普通包的形式出现在列表里,而是作为环境的“核心”
如何确认当前Python版本
我们看看这条日志:
(sparseo***) root@autodl-container-5fe44bab80-dc2c6e88:~# conda create -n sparse-1 python=3.8
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): | # 这里其实失败了
(sparseo***) root@autodl-container-5fe44bab80-dc2c6e88:~# python --version
Python 3.8.10
(sparseo***) root@autodl-container-5fe44bab80-dc2c6e88:~#
当我们执行命令 “conda create -n sparse-1 python=3.8” 时,还是会有这个报错,但此时我们执行命令:
conda info
或者更直接的:
python --version
就能够看到当前python的版本,即使 conda create -n [想创建的环境名],conda activate [想创建的环境名] 之后,再执行刚才那两个命令,也会发现已经装好了py38
但这行命令
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
还是没法成功执行,只能是使用conda创建环境,pip来安装依赖包啦
神奇的特性
在经过执行“conda create -n sparseo***”,加载显卡后,python --version找不到python,删除sparseo***环境后,命令“conda create -n sparseo*** python=3.8 -y”竟然成功执行了