【Python】报错荟萃

之前好几年的编程,遇到各种奇怪的报错,有的解决了有的没有,现在都忘了,我非常痛心。所以从现在(2023.05.10)开始对以后遇到的报错进行记录。

1.RuntimeError: Trying to backward through the graph a second time (or directly access saved variables after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved variables after calling backward.

解决方法:网上较多的是针对一个网络有多个输出分别进行梯度下降的情况,我遇到的则是Softmax和Parameter同时在一条语句中使用时报错,解决方法是去掉Softmax

2.File “D:\Projects\Flow\Flow_Forecast\venv\lib\site-packages\psycopg2_init_.py”, line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError

解决方法:这是一个很笼统的报错,以至于我没看出来。后来发现是字母大小写的问题,postgresql使用python新建表单和数据库时大写字母被强制转为小写,但在读取数据库和表的时候却分大小写,所以这边初始化报错了。建议postgresql中的名字都用小写。

3.TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: float64……

解决方法:强制类型转换 x.astype(None),变更为普通数组

4.numpy.core._exceptions._ArrayMemoryError: Unable to allocate 3.99 MiB for an array with shape (39, 13410) and data type object

解决方法:这是读取数据内存溢出的问题。重跑模型或者优化内存配置

5.ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’

解决方法:np.nan(a)中的a的类型有问题,修改为np.nan(a.astype(None))即可。

6.You are trying to merge on datetime64[ns] and object columns. If you wish to proceed you should use pd.concat

解决方法:这是在两个dateframe进行merge的时候出现的问题,需要将左右两个df的合并项格式进行统一。我这边报错是表1中的时间列为datetime64,表2中的时间列为object。

7.can’t convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, int64, int32, int16, int8, uint8, and bool.

解决方法:有变量x是object类型的,需要强制转换x.astype(float)

8.only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

解决方法:索引必须为整数,将index强制转换为int

9.OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized

解决方法:libiomp5md.dll重复, 可参考这边。我用的方法一。

10.Out of range float values are not JSON compliant

解决方法:json 字典中存在不是数的内容,改一下就行

11._pickle.PicklingError: Could not pickle the task to send it to the workers.

python中多进程在切换系统时出现报错,主要由于Parallel的默认参数在部分系统不适用,重新指定一个参数即可。
解决方法:
joblib.Parallel(self.n_jobs) ——> joblib.Parallel(self.n_jobs, backend=“threading”)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清流自诩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值