【python 深度学习】解决遇到的问题

目录

[一、RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb](#一、RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb)

[二、AttributeError: module 'tensorflow' has no attribute 'flags'](#二、AttributeError: module ‘tensorflow’ has no attribute ‘flags’)

[三、conda 更新 Please update conda by running](#三、conda 更新 Please update conda by running)

[四、to search for alternate channels that may provide the conda package you're looking for, navigate to](#四、to search for alternate channels that may provide the conda package you're looking for, navigate to)

[五、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal](#五、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal)


一、RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

问题:import torch时报错:RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

原因:这是numpy版本与python版本不匹配的问题

解决:

  1. 卸载原来版本的numpy
  2. 下载相匹配的numpy版本
    https://www.lfd.uci.edu/~gohlke/pythonlibs/找到对应版本的numpy,然后下载到本地
  3. 安装

二、AttributeError: module 'tensorflow' has no attribute 'flags'

问题:在我的code中是由该命令FLAGS = tf.flags.FLAGS引起的报错,主要原因是我下载的tensorflow是最新的版本2.1,将tensorflow修改为1.9版本即可。

解决:

(2)第二种方法,在tensorflow官方在线文档搜索tf.flags,通过观看下图可以看出flags模块已经移至compat.v1中,原命令修改为FLAGS = tf.compat.v1.flags.FLAGS即可。

三、conda 更新 Please update conda by running

问题:安装numpy第三方库的时候,输入后发现有个提示:有最新conda版本下载

复制代码
conda update -n base -c defaults conda

然后,我运行命令去更新conda,但是报错了:EnvironmentNotWritableError: The current user does not have write permissions to the target environment.

原因:conda装在虚拟机的C盘里没有权限写入,

解决:退出pycharm后,以管理员身份重新打开pycharm,再次输入命令进行更新conda。

发现,更新成功了。

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

问题:安装某个python包时(并不特别对于某个特定包,各种包有时都会出现这种情况 。会出现当前channel不可用,并报错,

原因:其实很简单,就是告诉你在这个指令的默认下载channel列表中找不到合适的安装包,它是建议你去anaconda官网里面去找与之匹配的安装包自己下载。

解决:

(1)你需要去 https://anaconda.org 这个网址,在上方的搜索条上搜索你要安装这个包的其他channel,下边展示一下如何找igraph的其他channel。

首先进入上述网址,你可以在上方看到搜索条,搜索numpy,会出现所有包名中包含"numpy"字段的包:

(2)接着在你的命令行窗口或Anaconda Prompt窗口对应的路径下运行页面中提供的任意一条命令即可。

(3)

五、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal

报错:

复制代码
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

解决方法:在加载模型的时候加上map_location='cpu'

相关推荐
捉鸭子12 分钟前
某音a_bogus vmp逆向
爬虫·python·web安全·node.js·js
曲幽23 分钟前
FastAPI 生产环境静态文件完全指南:从 /favicon.ico 404 到 HSTS 混合内容,一次全根治
python·fastapi·web·static·media·404·hsts·favicon·url_for
Dontla25 分钟前
Python asyncpg库介绍(基于Python asyncio的PostgreSQL数据库驱动)连接池、SQLAlchemy
数据库·python·postgresql
zh15702333 分钟前
如何编写动态SQL存储过程_使用sp_executesql执行灵活查询
jvm·数据库·python
2401_8242226938 分钟前
SQL报表统计数据量巨大_分批统计策略
jvm·数据库·python
X566141 分钟前
mysql如何处理连接数过多报错_调整max_connections参数
jvm·数据库·python
m0_609160491 小时前
MongoDB中什么是Hashed Shard Key的哈希冲突_哈希函数的分布均匀性分析
jvm·数据库·python
Ulyanov1 小时前
《现代 Python 桌面应用架构实战:PySide6 + QML 从入门到工程化》 开发环境搭建与工具链极简主义 —— 拒绝臃肿,构建工业级基座
开发语言·python·qt·ui·架构·系统仿真
wuxinyan1231 小时前
大模型学习之路03:提示工程从入门到精通(第三篇)
人工智能·python·学习
如何原谅奋力过但无声1 小时前
【灵神高频面试题合集01-03】相向双指针、滑动窗口
数据结构·python·算法·leetcode