LookupError:未知编码:cp0 [英] LookupError: unknown encoding: cp0

查看:119
本文介绍了LookupError:未知编码:cp0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7,python 2.7.2,pandas 0.11.0,django 1.4,wsgi和apache 2.2中。我有一个pandas脚本,如果我直接用python运行它,也可以正常工作,而且还可以在%python的ipython中运行。但是,当我在视图中运行熊猫时,出现 LookupError:未知编码:cp0。仅在视图内的熊猫中使用ols时才会发生这种情况。我也有些困惑,为什么py3compat.py在使用python 2.7时输入图片。另外,我看到了一些有关将打印的变量包装在str()中的文章,但是我不确定在这里如何应用。整个回溯是:

I am on window 7, python 2.7.2, pandas 0.11.0, django 1.4, wsgi and apache 2.2. I have a pandas script that works fine if I run it directly with python and also works in ipython with %run. However, when I run pandas in my view i get "LookupError: unknown encoding: cp0". This only happens when using ols in pandas within the view. I'm also a little confused why py3compat.py is entering the picture as i'm using python 2.7. Also, I have seen some posts about wrapping a printed variable in a str(), but I'm not sure how that would apply here. The whole traceback is:

Traceback (most recent call last):
model = pd.ols(y=df_loan['LogSpread'], x=df_loan['Dummy Rating'])
File "C:\\Python27\\lib\\site-packages\\pandas\\stats\\interface.py", line 135, in ols
return klass(**kwargs)
File "C:\\Python27\\lib\\site-packages\\pandas\\stats\\ols.py", line 43, in __init__
  import statsmodels.api as sm
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\api.py", line 3, in <module>
  import regression
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\regression\\__init__.py", line 1, in <module>
  from linear_model import yule_walker
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\regression\\linear_model.py", line 41, in <module>
  import statsmodels.base.model as base
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\base\\model.py", line 10, in <module>
from statsmodels.formula import handle_formula_data
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\formula\\__init__.py", line 4, in <module>
  from formulatools import handle_formula_data
File "C:\\Python27\\lib\\site-packages\\statsmodels-0.5.0-py2.7-win32.egg\\statsmodels\\formula\\formulatools.py", line 2, in <module>
  from patsy import dmatrices
File "build\\bdist.win32\\egg\\patsy\\__init__.py", line 70, in <module>
  _reexport("patsy." + child)
File "build\\bdist.win32\\egg\\patsy\\__init__.py", line 61, in _reexport
__import__(modname)
File "build\\bdist.win32\\egg\\patsy\\highlevel.py", line 18, in <module>
File "build\\bdist.win32\\egg\\patsy\\design_info.py", line 17, in <module>
File "build\\bdist.win32\\egg\\patsy\\util.py", line 385, in <module>
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\__init__.py", line 46, in <module>
  from .frontend.terminal.embed import embed
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\frontend\\terminal\\embed.py", line 39, in <module>
  from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\frontend\\terminal\\interactiveshell.py", line 33, in <module>
  from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\core\\interactiveshell.py", line 61, in <module>
  from IPython.core.prompts import PromptManager
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\core\\prompts.py", line 138, in <module>
  HOME = py3compat.str_to_unicode(os.environ.get("HOME","//////:::::ZZZZZ,,,~~~"))
File "C:\\Python27\\lib\\site-packages\\ipython-0.13.1-py2.7.egg\\IPython\\utils\\py3compat.py", line 18, in decode
  return s.decode(encoding, "replace")
LookupError: unknown encoding: cp0

感谢一堆!

推荐答案

关闭Spyder。

打开Anaconda提示符并输入: set PYTHONIOENCODING = UTF-8
或者,创建一个名称为 PYTHONIOENCODING 且值为 UTF-8 的环境变量。

Open Anaconda Prompt and type in: set PYTHONIOENCODING=UTF-8. Or, create an environment variable with name PYTHONIOENCODING and value UTF-8.

键入 spyder 重新开始。

这篇关于LookupError:未知编码:cp0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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