栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python程序运行是出现的bug和解决方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python程序运行是出现的bug和解决方法

安装虚拟环境

1、安装conda
2、conda info -e 查看已经存在的conda的虚拟环境
3、conda create -n your_env_name python=x.x 创建虚拟环境
4、成功后,pip install 报名 安装需要的包,出错的话,看一下下面的
5、source activate your_env_nam 激活虚拟环境就行

出现的问题 pytorch加载device on cuda,出现错误
RuntimeError: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

解答1:
1.检查python中 pytorch版本

python
import torch 
torch.__version__()
#1.10.2+cuda102

2、升级python到3.8(conda install python==3.8)升级方法如下,然后,从新按照环境就可以解决问题

pip安装是出现错误
 Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pipenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/pipenv/ 

解决方案:
可用源
豆瓣:http://pypi.douban.com/simple/

清华:https://pypi.tuna.tsinghua.edu.cn/simple

清华大学的pip源,它是官网pypi的镜像,每隔5分钟同步一次,推荐使用

sudo pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
anaconda虚拟环境中,python版本升级失败
使用pip install python=3.8失败

解决方案
使用conda安装,conda install python==3.8既可,然后之前安装的比如pandas等第三方包都会自动卸载,在升级成功之后需要重新下载对应的包

pip安装pytorch之后,运行失败

AssertionError: Torch not compiled with CUDA enabled
原因是安装了pytorch的cpu版本,如果要使用cuda需要按照gou版本的pytorch,命令行conda install pytorch-gpu
命令不要写错了哦,如果写错了比如我 conda install pytorch-gpu

conda install 之后使用pip安装
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.  
翻译:pip的依赖项解析器当前未考虑安装的所有包。此行为是以下依赖项冲突的根源
pysptk 0.1.20 requires decorator, which is not installed.
pysptk 0.1.20 requires scipy, which is not installed.
nnmnkwii 0.1.1 requires scikit-learn, which is not installed.
nnmnkwii 0.1.1 requires scipy, which is not installed.
nnmnkwii 0.1.1 requires tqdm, which is not installed.

当前期安装的包是使用conda install 安装的,后面使用pip install 安装时会出现这个问题,因为conda安装时会检查之前安装的所有包,而pip不会,这样就会很容易导致冲突,所以需要切换到conda install 重新安装

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767382.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号