【conda】利用Conda创建虚拟环境,Pytorch各版本安装教程(Ubuntu)

@TOC
conda 系列:
1. conda指令教程
2. 利用Conda创建虚拟环境,安装Pytorch各版本教程(Ubuntu)

1. 利用Conda创建虚拟环境

nolo@nolo:~/sun/SplaTAM$ conda create -n splatam  python==3.10

查看结果:

(splatam) nolo@nolo:~/sun/SplaTAM$ conda info -e

详细见 【python】Conda强大的包/环境管理工具

2. 利用Conda创建虚拟环境中Pytorch各版本安装教程

nvida-smi 查看cuda兼容版本号,最高
在这里插入图片描述
安装Pytorch
激活环境之后,就可以在环境中安装pytorch框架。 进入Pytorch官网点击install进行选择。
在这里插入图片描述
如上图,如果需要安装的是pytorch_1.7版本,可以直接选择系统、安装方式和CUDA版本,复制下方红色框中的命令到终端即可安装。 需要其他版本pytorch可以点击图中绿色框内的选项,查看pytorch的早期版本。
例如pytorch1.4,复制相应的命令到终端即可安装。

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2 -c pytorch 
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch 

3. PackagesNotFoundError: The following packages are not available from current channels 解决方案

在这里插入图片描述

解决方法一:将conda-forge添加到搜索路径上
首先,当出现这种报错时,应该首先尝试使用以下命令将conda-forge channel添加到你的channel列表中:

conda config --append channels conda-forge

它告诉conda在搜索软件包时也要在conda-forge channel上查看。

然后你就可以尝试利用如下命令再次安装

conda install 包名

原因在于:channel可以看成是托管python包的服务器,当无法通过标准channel获得python包时,社区驱动的conda-forge通常是一个很好的地点。大部分问题都可以利用这条语句解决。

方法二:利用报错提示,进入annaconda网站利用命令解决
当添加上述语句仍然出现错误,安装某个python包时(并不特别对于某个特定包,各种包有时都会出现这种情况 。会出现当前channel不可用,并报错:

PackagesNotFoundError: The following packages are not available from current channels:

报错的完整显示:
上面这个报错的即可觉方案:见链接

Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.


PackagesNotFoundError: The following packages are not available from current channels:

  - igraph

Current channels:

  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

解决办法报错中有:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

你需要去 https://anaconda.org 这个网址,在上方的搜索条上搜索你要安装这个包的其他channel,下边展示一下如何找igraph的其他channel
进入上述网址,你可以在上方看到搜索条:

4. PackagesNotFoundError: The following packages are not available from current channels 解决办法

在这里插入图片描述
解决方法一:
添加 Anaconda Python 免费仓库:


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

检查Anaconda的config:查看channel个数以及格式,显然觉得有一个是有问题的:

conda config --show 

参照 conda config 说明,移除某些channel :

conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' 

或者可以使用 下面命令换回默认源:

conda config --remove-key channels
不过还有简单粗暴地方法:

直接修改conda的配置,一般在当前用户路径下,比如C:\Users\Administrator.condarc.condarc具体内容如下:show_channel_urls: truechannels:

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

现在清华镜像不能使用了,删除这个镜像,可以试一下下面的镜像:

http://pypi.douban.com/simple/ 豆瓣镜像
http://mirrors.aliyun.com/pypi/simple/ 阿里镜像

解决方法二:

anaconda search -t conda X

X为要安装的包

conda install -c https://conda.anaconda.org/X-path  X

在这里插入图片描述

conda config --add channels  https://anaconda.org

5.

猜你喜欢

转载自blog.csdn.net/Darlingqiang/article/details/134872917