Python 使用pip安装uwsgi时'ascii'编解码器无法解码错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17931726/
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-08-19 09:31:16  来源:igfitidea点击:

'ascii' codec can't decode error when use pip to install uwsgi

pythondjangouwsgi

提问by Yitong Zhou

I am setting up uwsgi following this tutorial: https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. I run pip install uwsgiwithin virtualenv, but get the problem as follows:

我正在按照本教程设置 uwsgi:https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html 。我pip install uwsgi在virtualenv中运行,但问题如下:

Command /home/timyitong/superleagues/bin/python -c "import setuptools;__file__='/home/timyitong/superleagues/build/uwsgi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Z9h8Jn-record/install-record.txt --single-version-externally-managed --install-headers /home/timyitong/superleagues/include/site/python2.6 failed with error code 1 in /home/timyitong/superleagues/build/uwsgi
Traceback (most recent call last):
  File "/home/timyitong/superleagues/bin/pip", line 9, in <module>
    load_entry_point('pip==1.4', 'console_scripts', 'pip')()
  File "/home/timyitong/superleagues/lib/python2.6/site-packages/pip/__init__.py", line 148, in main
    return command.main(args[1:], options)
  File "/home/timyitong/superleagues/lib/python2.6/site-packages/pip/basecommand.py", line 169, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 54: ordinal not in range(128)

It seems like a decoding problem, but how to resolve that? My system environment is:

这似乎是一个解码问题,但如何解决呢?我的系统环境是:

Ubuntu 10.04
Django==1.5.1
South==0.8.1
distribute==0.7.3
wsgiref==0.1.2

Notice: the answer to this problem might differ due to different operating environments. The comments of Twil actually solved my problem in OS X.

注意:此问题的答案可能因操作环境不同而有所不同。Twil 的评论实际上解决了我在 OS X 中的问题。

回答by leela

Try installing first libevent-devel and python-devel

尝试先安装 libevent-devel 和 python-devel

yum install libevent-devel python-devel

and then installing

然后安装

pip install uwsgi

回答by hugleecool

It's a question asked a year ago? I come here by Google. I notice that the asker is Chinese, same as me. So, maybe we face the same problem. Oh, sorry for my bad English!

这是一年前问的问题?我是通过 Google 来到这里的。我注意到提问者和我一样是中国人。所以,也许我们面临同样的问题。哦,对不起我的英语不好!

I HAVE FOUND THE RIGHT ANSWER!

我找到了正确的答案!

It is because when Python installs some packages, it will check the Windows Registry, some Chinese software like Aliwangwang import 'gbk' value to the HKEY_CLASSES_ROOT. So Python doesn't work.

这是因为Python在安装一些包的时候会检查Windows Registry,一些中文软件比如阿里旺旺会在HKEY_CLASSES_ROOT里导入'gbk'的值。所以Python不起作用。

It can be solved like this:

可以这样解决:

open C:\Python27\Lib\ mimetypes.py with Notepad ++ or other editor, then search the line " default_encoding = sys.getdefaultencoding()". add codes to the line above like this:

使用 Notepad ++ 或其他编辑器打开 C:\Python27\Lib\ mimetypes.py,然后搜索“default_encoding = sys.getdefaultencoding()”行。将代码添加到上面的行中,如下所示:

if sys.getdefaultencoding() != 'gbk':
    reload(sys)
    sys.setdefaultencoding('gbk')
    default_encoding = sys.getdefaultencoding()

回答by Yang_2333

hugleecool's solution is good. Another way to solve this is to find Control Panel and change the system's non Unicode program's language.

hubleecool 的解决方案很好。解决此问题的另一种方法是找到控制面板并更改系统的非 Unicode 程序的语言。

For Chinese system, i think the default value is Chinese, you could change it to English and it will solve all the similar decode problems.

对于中文系统,我认为默认值是中文,您可以将其更改为英文,它将解决所有类似的解码问题。

回答by TheDimLebowski

I had the same problem. In my case, on top of the above suggestions I had to run:

我有同样的问题。就我而言,除了上述建议之外,我还必须运行:

sudo apt-get install build-essential

回答by Lordn__n

Check that you have installed python-dev

检查您是否已安装 python-dev