Anaconda已下载Pytorch但是无法在python环境中import torch

1.背景

最近搭建Pytorch环境,但是安装好了以后反复出现如下问题

Anaconda已下载Pytorch但是无法在python环境中import torch
无法在python环境下import torch,但是我使用pip list命令发现我是已经下载了的
Anaconda已下载Pytorch但是无法在python环境中import torch

; 2.查错

我将Pytorch卸载后并在新的虚拟环境中反复对照教程进行尝试了依然还是import不了,并且这个问题百度也解决不了
然后我尝试了直接pip install torch

Anaconda已下载Pytorch但是无法在python环境中import torch
结果发现它报的错出现的提示就是我之前import torch时报错的原因

3.确定标题错误的产生是因为创建虚拟环境python版本低了应该要>=3.7(处理测试过程中出现的问题)

1.我重新创建了一个虚拟环境并设置其python版本为3.8
conda create –name hahaha python=3.8
2.然后按照搭建Pytorch环境的步骤来
3.在python环境中import torch,但是等了很久很久,我以为又失败了,但是我重启Anaconda prompt重新进入环境后import torch一下子就成功了,所以小伙伴们如果一会还没有import成功可以试试重启
4.然后我试着导入另外两个包发现出现这个问题

Anaconda已下载Pytorch但是无法在python环境中import torch
这时候只需要exit()退出python环境
然后输入
pip install PySoundFile
就可以啦
Anaconda已下载Pytorch但是无法在python环境中import torch

; 4.另附上Pytorch环境搭建教程(Anaconda)

1.准备工作

1.首先在Anaconda prompt中运行
conda update conda
//将conda更新到最新版本会方便后续操作进行
2.配置清华源,将.condarc文件更改成以下内容操作详细步骤参考

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 –set show_channel_urls yes
conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

3.创建虚拟环境操作详细步骤参考
4.进入虚拟环境
activate xxx
//xxx为你创建的虚拟环境名
5.若先前已下载pytorch包但是import失败,则一般是下载了但并不成功,这种情况建议先删除安装目录Anaconda->pkgs->pytorch的文件夹即它的taz包然后重新下载pytorch

2.安装Pytorch

1.进入Pytorch官网
2.查看电脑配置,全局搜索里搜索设备管理器

Anaconda已下载Pytorch但是无法在python环境中import torch
找到目录中的显示适配器,若其中为AMD则无法使用CUDA加速,下述操作中不要选择CUDA,若为图中则可以选择CUDA
3.页面下拉
Anaconda已下载Pytorch但是无法在python环境中import torch
第一行选择第一个稳定版本
其他几行根据自己的需要来,最后一行的选择参考操作2
4.将上图中灰色命令行复制粘贴到Anaconda promt中运行即可
//若出现httperror或者下载异常慢一般为清华源未配置好

; 3.测试

1.进入python环境,命令行输入
python
2.输入
import torch
3.若能正常进入下一个命令行则安装成功

Original: https://blog.csdn.net/qq_48078689/article/details/124306710
Author: gcj_future
Title: Anaconda已下载Pytorch但是无法在python环境中import torch

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/705681/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球