我在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
非常感谢!
答案 0 :(得分:3)
关闭Spyder。
打开Anaconda Prompt并输入:set PYTHONIOENCODING = UTF-8。 或者,创建一个名为“PYTHONIOENCODING”且值为“UTF-8”的环境变量。
输入spyder重新开始。
答案 1 :(得分:0)
我也遇到了这个问题,并且使用了很多方法。但是我也失败了,但是,当我重新启动Spyder并重新运行我的程序时,这个问题已经解决了,这太棒了,我建议你可以试试这个意思
答案 2 :(得分:0)
我也使用spyder遇到了这个问题但是当我打开一个新的控制台时,它再次运行起来很容易解决。