pycharm运行的时候出现module 'sys' has no attribute 'setdefaultencoding'错误的解决方法

U盘安装单系统ubuntu10.04之全过程&拔掉U盘后系统无法启动 借助U盘把电脑装成ubuntu单系统之过程记录,以及遇到拔掉U盘后系统无法启动问题,电脑就显示: Non-System disk or disk error, replace and strike any key when ready 阅读详情

运行代码的时候出现了module 'sys' has no attribute 'setdefaultencoding'错误,在网上试了很多方法都不行,最终发现删掉external libraries-site-packages里面的sitecustomize.py文件就行了。

因为之前在网上试了如下的方法:


但是python3不支持这个setdefaultencoding这个语句,所以才导致了报错,所以删掉那个文件就行了。

Python错误:模块对象没有属性‘setdefaultencoding‘问题的解决方法 Python编程中,'AttributeError: ‘module’ object has no attribute ‘setdefaultencoding’'错误通常发生在旧版本的Python中,因为’setdefaultencoding’属性已在Python 3中被移除。要解决这个问题,您可以删除对’setdefaultencoding’的引用,让Python使用默认的UTF-8编码,或者使用其他编码库来设置默认的字符串编码。在旧版本的Python中,我们可以使用该属性来设置默认的字符串编码。 阅读详情

相关推荐

出现 Error occurred during initialization of VMagent library failed Agent OnLoad 解决方法

ntelliJ IDEA启动时出现"Agent library failed to load"错误,主要原因是JVM代理加载失败。解决方法包括:1)完全卸载并删除用户目录下的JetBrains配置文件;2)检查并修改idea64.exe.vmoptions文件,确保路径正确并删除不必要的-javaagent参数;

码农研究僧的博客 2430

解决NameError: name ‘reload‘ is not defined

解决NameError: name ‘reload’ is not defined

努力让自己发光,对的人才能迎着光而来 2万+

IEC 61800-5-1-2022 (英文原版908页)可调速电力驱动系统 第5-1部分:安全要求电气、热力和能源.rar

IEC 61800-5-1-2022 (英文原版908页)可调速电力驱动系统 第5-1部分:安全要求电气、热力和能源.rar可复制内容高清原版。

python报错】AttributeError: module ‘sys‘ has no attribute ‘setdefaultencoding‘

python报错】AttributeError: module 'sys' has no attribute 'setdefaultencoding'

Lucilla's blog 1971

module ‘sys‘ has no attribute ‘setdefaultencoding‘

如果你的代码中出现了这个错误,很可能是因为你正在尝试在Python 3.3或更高版本中运行设计运行Python 2.x中的代码。在Python 2.x中,sys模块有一个setdefaultencoding()方法,可以用来设置默认字符串编码。如果你需要运行的是自己的代码,请移除对sys.setdefaultencoding()的调用,因为在Python 3中这是不必要的,并且不再支持。如果你正在维护一个第三方库,并且该库需要在Python 3环境中运行,请确保它已经更新到与Python 3兼容的版本。

计算机辅助工程 881

AttributeError: module 'sys' has no attribute 'setdefaultencoding

Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding 基于python3.6.1版本,在一个.py文件中,加入这3行: import requests, re, sys reload(sys) sys.setdefaultencoding("utf-8") 出现这样的错误: sys.setde...

topqy的博客 2万+

Python】已解决AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’

这个函数在Python 2中用于设置默认的字符串编码,但在Python 3中,由于所有的字符串都是Unicode字符串,因此默认编码的设置变得不再必要,且可能导致混乱,所以该方法被移除了。通过遵循上述指南和最佳实践,你可以避免“AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’”这样的错误,并确保你的代码在各种环境中都能稳定运行。在Python 3中,你通常不需要(也不能)设置默认的字符串编码。

屿小夏.的知识博客 1964

Python问题分析:AttributeError: module 'sys' has no attribute 'setdefaultencoding'

问题描述AttributeError: module 'sys' has no attribute 'setdefaultencoding'样例代码import sys sys.setdefaultencoding('utf-8')问题分析目前的Python版本是3.6.1,其默认的编码格式是utf-8。 》import sys 》sys.getdefaultencoding()

木小鱼的笔记 3万+

python报错AttributeError: module ‘sys‘ has no attribute ‘setdefaultencoding‘

遇到报错: AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’ 是因为python3默认使用的是utf-8的编码,所以只需要把这一句:sys.setdefaultencoding(‘utf8’)删除即可

weixin_46235937的博客 6875

Python3异常:AttributeError: module 'sys' has no attribute 'setdefaultencoding'

错误 2. 原因:Python3字符串默认编码unicode, 所以sys.setdefaultencoding也不存在了 删除此行代码,执行通过

LI_AINY的博客 1万+

module 'sys' has no attribute 'setdefaultencoding'

https://blog.csdn.net/m0_37870649/article/details/79431690

Winnycatty的博客 1675

【BUG】已解决AttributeError: module ‘sys‘ has no attribute ‘setdefaultencoding‘

AttributeError: module ‘sys‘ has no attribute ‘setdefaultencoding‘

m0_73367097的博客 1302

Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding'

基于python3.6.1版本,在一个.py文件中,加入这3行: import requests, re, sys reload(sys) sys.setdefaultencoding("utf-8") 出现这样的错误: sys.setdefaultencoding("utf-8") AttributeError: module 'sys' has no attribut...

weixin_30835649的博客 545

AttributeError: module 'sys' has no attribute 'setdefaultencoding'

import sys reload(sys) sys.setdefaultencoding("utf-8") 报错: reload 未声明 然后 import sys sys.setdefaultencoding("utf-8") 报错 AttributeError:module'sys'has no attribute'setdefaultenco...

weixin_30497527的博客 264

Python3-AttributeError: module 'sys' has no attribute 'setdefaultencoding

Python3字符串默认编码unicode, 所以sys.setdefaultencoding不存在 去掉 sys.setdefaultencoding('utf8')

zhangvalue的博客 1894

Python报错“AttributeError: module 'sys' has no attribute 'setdefaultencoding'问题”

Python3中写法: import imp import sys imp.reload(sys) Python2中写法: import sys reload(sys) sys.setdefaultencoding("utf-8") 转载于:https://www.cnblogs.com/yznmj-112/p/11004872.html...

weixin_30420305的博客 5193

Python报错已解决AttributeError: module ‘sys‘ has no attribute ‘setdefaultencoding‘

Python编程中,有时会遇到试图设置系统的默认编码,但却遇到了`AttributeError: module 'sys' has no attribute 'setdefaultencoding'`的错误。这个问题通常发生在尝试使用`sys.setdefaultencoding`来设置默认编码时。本文将探讨如何解决这个问题。

鸽芷咕的博客 1507

Python AttributeError: module 'sys' has no attribute 'setdefaultencoding'

Python3默认的编码的类型是utf-8,所以需要删掉sys.setdefaultencoding(“utf-8”)这句代码。

yuanyuanwy的博客 774

python中的setdefaultencoding函数使用

#!/usr/bin/env python #encoding: utf-8 import sys #引用sys模块进来,并不是进行sys的第一次加载 reload(sys) #重新加载sys sys.setdefaultencoding('utf8') ##调用setdefaultencoding函数 可以正确的执行,可是下面的代码会出错 #!/usr/bin

3064
下一篇: 将字符串转成json格式的正则表达式
autotest00
博客等级 码龄8年 14粉丝 3原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值