pandas 查找错误:未知编码:cp0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17096631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:54:47  来源:igfitidea点击:

LookupError: unknown encoding: cp0

pythondjangoencodingpandas

提问by user1604594

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:

我在窗口 7、python 2.7.2、pandas 0.11.0、django 1.4、wsgi 和 apache 2.2。我有一个 Pandas 脚本,如果我直接使用 python 运行它并且在 ipython 中使用 %run 也可以正常工作。但是,当我在视图中运行 Pandas 时,我收到“LookupError: unknown encoding: cp0”。这只发生在视图中的 Pandas 中使用 ols 时。我也有点困惑为什么 py3compat.py 在我使用 python 2.7 时进入图片。另外,我看过一些关于在 str() 中包装打印变量的帖子,但我不确定这将如何应用于这里。整个回溯是:

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

Thanks a bunch!

谢谢一堆!

回答by Vishal Gupta

Close Spyder.

关闭 Spyder。

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

打开 Anaconda Prompt 并输入:set PYTHONIOENCODING=UTF-8. 或者,创建一个具有 namePYTHONIOENCODING和 value的环境变量UTF-8

Type spyderto start again.

键入spyder以重新开始。

回答by user7622183

I also meet with this problem, and use many methods. but I also failed, however, when I restart Spyder and run my program again, this problem have been solved, It's amazing, and I advise you can try this mean

我也遇到这个问题,用了很多方法。但是我也失败了,然而,当我重新启动Spyder并再次运行我的程序时,这个问题已经解决了,太神奇了,我建议你可以试试这个意思

回答by Jartican

I also had this problem using spyder however when I open a new console it works again so easy fix.

我在使用 spyder 时也遇到了这个问题,但是当我打开一个新的控制台时,它又可以很容易地修复了。