Python新手入门常见报错解决

总结如下,供参考交流。

Python报错:安装librosa,提示Cannot uninstall ‘llvmlite’如何解决?


详细报错描述:

ERROR: Cannot uninstall ‘llvmlite’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
  • 解决pip install librosa --ignore-installed llvmlite

  • 参考链接:https://blog.csdn.net/Mark_2018/article/details/104311175

Python报错:Empty suite


  • 此问题一般是文件名涉及到test类了,删除文件命名中的test字符即可解决
  • 原文件命名:test_rm_pic_watermark.py
  • 修正后:demo_rm_pic_watermark.py

Python报错:str字符串操作中append失败


  • 报错:AttributeError: 'str' object has no attribute 'append'
  • 原因:字符串没有append方法,append方法是存在于list中。
  • 解决:直接用 + 来实现连接追加即可。

Python报错:txt读入后,再写入新txt,输出中文乱码


  • 文本输入与输出,编码方式统一要设置为utf8
  • 原代码:f_in = open(in_path)
  • 改后:f_in = open(in_path, "r", encoding='utf-8')
  • Python默认是按utf8读取的,如果有中文字符,建议先强制通用utf8编码。
  • 要读取非UTF-8编码的文本文件,需要给open()函数传入encoding参数,GBK编码。

from numpy import *和import numpy as np的模块导入的区别


  • 前者可以直接调用numpy模块的函数,不用加前缀,如eye(4)
  • 后者要加简写,便于区分函数来自哪个模块,如np.eye(4)
  • eye函数,生成4x4的单位矩阵

持续更新中


最近更新于:2022年1月4日

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值