解决python问题 Traceback (most recent call last)

作者:叶片儿 时间:2021-10-31 06:17:49 

python运行问题Traceback (most recent call last)

出现报错

traceback(most recent call last) 
......
......
importError:No module named lxml

解决方案一般是打开cmd 执行命令pip install xxxx(缺失的包,例如lxml)

当然也有例外的,具体可参考下面的问题及其解决方法。

问题1:No module named 'requests’

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

解决方法

打开cmd,

然后执行命令:pip install requests

解决python问题 Traceback (most recent call last)

问题2 No module named 'lxml&rsquo;

解决python问题 Traceback (most recent call last)

解决方法:

打开cmd,

然后执行命令:pip install lxml

解决python问题 Traceback (most recent call last)

问题3 UnicodeEncodeError:

&lsquo;ascii&rsquo; codec can&rsquo;t encode characters in position 0-78: ordinal not in range(128)

解决python问题 Traceback (most recent call last)

解决方法:

在python代码所在的文件头加上如下语句块

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

如果加入以上代码块引入python中print函数失灵的问题,那么就将如上代码块替换为如下代码块

import sys #这里只是一个对sys的引用,只能reload才能进行重新加载
stdi,stdo,stde=sys.stdin,sys.stdout,sys.stderr
reload(sys) #通过import引用进来时,setdefaultencoding函数在被系统调用后被删除了,所以必须reload一次
sys.stdin,sys.stdout,sys.stderr=stdi,stdo,stde

然后运行python文件即可

问题4 No module named 'cv2&rsquo;

解决python问题 Traceback (most recent call last)

直接输入pip install cv2命令安装时发现也会提示出错

解决python问题 Traceback (most recent call last)

最后利用下面的命令安装就成功了

pip install opencv-python

解决python问题 Traceback (most recent call last)

如果还是出错的话,在重新运行一次pip install opencv-python命令

问题5 No module named 'tqdm&rsquo;

解决python问题 Traceback (most recent call last)

解决方法:

执行命令:pip install tqdm


解决python问题 Traceback (most recent call last)

问题6 No module named 'PIL&rsquo;

解决python问题 Traceback (most recent call last)

解决方法:

使用命令:pip install PIL时,出现了另一个错误,查了一下,原来是因为 PIL 已经被 Pillow 所替代了

解决python问题 Traceback (most recent call last)

于是执行命令pip install Pillow,成功了

解决python问题 Traceback (most recent call last)

问题7 Syntaxerror:non-ascii character&rsquo;\xe6&rsquo; in file

解决python问题 Traceback (most recent call last)

解决方法:

所有出现报错的文件中的文件头部添加注释:

# coding=utf-8

或者

# coding=utf-8

问题8 No module named 'openpyxl&rsquo;

解决python问题 Traceback (most recent call last)
 

解决方法:

执行命令:pip install openpyxl

解决python问题 Traceback (most recent call last)

来源:https://blog.csdn.net/weixin_43978056/article/details/105940157

标签:python,Traceback,most,recent,call,last
0
投稿

猜你喜欢

  • DJANGO-ALLAUTH社交用户系统的安装配置

    2022-10-03 11:29:08
  • ASP实现防止网站被采集代码

    2011-03-25 10:40:00
  • python合并已经存在的sheet数据到新sheet的方法

    2023-07-25 18:05:51
  • python中pip的使用和修改下载源的方法

    2023-08-04 21:33:41
  • pydev使用wxpython找不到路径的解决方法

    2023-02-23 05:01:01
  • php cookie中点号(句号)自动转为下划线问题

    2023-09-07 11:05:04
  • Flask框架通过Flask_login实现用户登录功能示例

    2021-07-19 07:15:38
  • Python插入Elasticsearch操作方法解析

    2021-08-30 01:47:09
  • 如何选择合适的MySQL存储引擎

    2009-02-04 13:02:00
  • Python 使用 prettytable 库打印表格美化输出功能

    2021-10-25 08:42:54
  • 基于python实现双向链表

    2022-02-17 04:06:44
  • Python实现制度转换(货币,温度,长度)

    2022-01-02 00:42:25
  • Python 多进程并发操作中进程池Pool的实例

    2022-06-28 16:31:37
  • Python制作豆瓣图片的爬虫

    2021-11-24 05:53:05
  • 解析:轻松了解 MySQL中损坏的MyISAM表

    2009-02-23 17:30:00
  • Python数据结构队列解决约瑟夫斯问题

    2022-01-07 03:20:53
  • 使用Pytorch训练two-head网络的操作

    2023-04-06 14:15:59
  • Python实现葵花8号卫星数据自动下载实例

    2021-09-26 13:40:25
  • Asp生成RSS的类_给网站加上RSS

    2011-04-19 11:06:00
  • python文件和目录操作函数小结

    2022-02-21 21:45:23
  • asp之家 网络编程 m.aspxhome.com