AttributeError:'module'对象没有属性'setdefaultencoding' [英] AttributeError: 'module' object has no attribute 'setdefaultencoding'

查看:499
本文介绍了AttributeError:'module'对象没有属性'setdefaultencoding'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试安装xadmin(这是一个django的插件,用于使用twitter引导的backoffice)。但是当我运行我的项目时,我的PyCharm终端中出现以下错误:

I try to install xadmin (it's a django's plugin for use the backoffice with twitter's bootstrap). But when I run my project, I have the following error in my PyCharm terminal :

File "C:\Python34\lib\site-packages\xadmin\sites.py", line 10, in <module>
sys.setdefaultencoding("utf-8")
AttributeError: 'module' object has no attribute 'setdefaultencoding'

这是xadmin插件中sites.py的源代码摘录:

This is the extract of source code from sites.py in xadmin plugin :

import sys
from functools import update_wrapper
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models.base import ModelBase
from django.views.decorators.cache import never_cache
from imp import reload

reload(sys)
sys.setdefaultencoding("utf-8")

该项目正在运行python 3.4解释器和Django 1.7.1。 xadmin的版本是0.5.0

The project is running with python 3.4 interpreter and Django 1.7.1. The xadmin's version is 0.5.0

我可以做什么?

推荐答案

p> Python 3没有 sys.setdefaultencoding()函数。它不能通过 reload(sys)恢复,就像它可以在Python 2(你真的不应该在任何情况下)。

Python 3 has no sys.setdefaultencoding() function. It cannot be reinstated by reload(sys) like it can on Python 2 (which you really shouldn't do in any case).

由于Python 3上的默认值是UTF-8 已经,所以在这些语句中没有任何意义。

Since the default on Python 3 is UTF-8 already, there is no point in leaving those statements in.

在Python 2中,使用 sys.setdefaultencoding()用于对隐式编码问题(由连接字节串和unicode值以及其他这种混合类型的情况引起),而不是而不是自己解决问题。 Python 3没有隐含的编码和解码,所以使用石膏设置不同的编码将无异于。

In Python 2, using sys.setdefaultencoding() was used to plaster over implicit encoding problems (caused by concatening byte strings and unicode values, and other such mixed type situations), rather than fixing the problems themselves. Python 3 did away with implicit encoding and decoding, so using the plaster to set a different encoding would make no difference anyway.

但是,如果这是第三方库那么你可能会遇到其他问题,因为它显然没有与Python 3兼容。

However, if this is a 3rd-party library, then you probably will run into other problems as it clearly has not been made compatible with Python 3.

这篇关于AttributeError:'module'对象没有属性'setdefaultencoding'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆