LookupError: unknown encoding: cp0

2024/10/2 20:33:32

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 decodereturn s.decode(encoding, "replace")
LookupError: unknown encoding: cp0

Thanks a bunch!

Answer

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.

https://en.xdnf.cn/q/70810.html

Related Q&A

Cant activate Python venv in Windows 10

I created a virtual environment with python -m venv myenv from the command prompt, but I dont know how to activate it. I tried executing activate.bat from the command prompt but it does not activate.In…

Opening file path not working in python [duplicate]

This question already has answers here:open() gives FileNotFoundError / IOError: [Errno 2] No such file or directory(11 answers)Closed last year.I am writing a database program and personica is my test…

Cython: Segmentation Fault Using API Embedding Cython to C

Im trying to embed Cython code into C following Oreilly Cython book chapter 8. I found this paragraph on Cythons documentation but still dont know what should I do:If the C code wanting to use these fu…

Computing AUC and ROC curve from multi-class data in scikit-learn (sklearn)?

I am trying to use the scikit-learn module to compute AUC and plot ROC curves for the output of three different classifiers to compare their performance. I am very new to this topic, and I am struggli…

Nested dictionary

I am working on some FASTA-like sequences (not FASTA, but something I have defined thats similar for some culled PDB from the PISCES server).I have a question. I have a small no of sequences called nCa…

How to create a Python script to automate software installation? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

Using __str__() method in Django on Python 2

I am Learning Django using the Django project tutorial. Since I use python 2.7 I am unable to implement the following in python 2.7:from django.db import modelsclass Question(models.Model): # ...def _…

Losing merged cells border while editing Excel file with openpyxl

I have two sheets in an Excel file and the first one is a cover sheet which I dont need to edit. There are a few merged cells in the cover sheet, and when I edit the file using openpyxl, without even t…

Reset CollectorRegistry of Prometheus lib after each unit test

I have a class A that initializes a Counter in its initfrom prometheus_client import Counter class A:def __init__(self):self.my_counter = Counter(an_awesome_counter)def method_1(self):return 1def metho…

Why does Django ORM allow me to omit parameters for NOT NULL fields when creating an object?

Stupid question time. I seem to be able to create an object for a Django model even though I omit a column that was defined as NOT NULL and I dont understand why. Heres my model:class Movie(models.Mo…