7

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

Thanks a bunch!

user1604594
  • 93
  • 1
  • 2
  • 6
  • That is very weird. Do this in a console `chcp` to see whats the current codepage you're using. – Paulo Bu Jun 13 '13 at 20:46
  • Active code page: 437 – user1604594 Jun 13 '13 at 21:08
  • I did a big of further debugging. It seems like I can't import IPython in the first place. The traceback starts at from .frontend.terminal.embed import embed. – user1604594 Jun 18 '13 at 00:05
  • 1
    So this is a terrible solution but it works on my machine. I went into the file IPython\core\prompts.py and I changed HOME = py3compat.str_to_unicode(os.environ.get("HOME","//////:::::ZZZZZ,,,~~~")) to HOME = py3compat.str_to_unicode(os.environ.get("HOME","//////:::::ZZZZZ,,,~~~"), 'cp437'). I also did the same for USER and HOSTNAME which is a few lines beneath that. – user1604594 Jun 18 '13 at 22:48

4 Answers4

9

Close Spyder.

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

Type spyder to start again.

gibbone
  • 2,300
  • 20
  • 20
Vishal Gupta
  • 805
  • 14
  • 15
0

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

0

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

0

conda create -n py2 python=2.7 anaconda jupyter spyder PYTHONIOENCODING=UTF-8 This does NOT work: PackagesNotFoundError: The following packages are not available from current channels:

  • pythonioencoding=UTF-8
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 14 '21 at 04:36
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/29817397) – Rishabh Deep Singh Sep 14 '21 at 08:32