11

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

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.

Yitong Zhou
  • 1,155
  • 4
  • 22
  • 42
  • 5
    Just guess try running `LC_ALL=C pip install uwsgi` – twil Jul 29 '13 at 19:46
  • @twil it seems solve the decode error, but it changes to another error. Do you think this is a total different error? Command /usr/bin/python -c "import setuptools; __file__='/home/timyitong/superleagues/build/uwsgi/setup.py'; execfile('/home/timyitong/superleagues/build/uwsgi/setup.py')" install --single-version-externally-managed --record /tmp/pip-hMl7E8-record/install-record.txt --install-headers /home/timyitong/superleagues/lib/include failed with error code 1 – Yitong Zhou Jul 29 '13 at 20:07
  • Yes, it looks like totaly different problem. What platform are you installing to? I've just installed `uwsgi` to virtualenv in my Ubuntu 13.04 without any problems. – twil Jul 29 '13 at 20:14
  • For Windows users, note that this happens when you have a Chinese (potentially any non-English installation, but not tested otherwise) system. Python fails to detect system encoding (this is not linux, so no `LANG` or `LC_ALL` by default), and crashes when it reads Chinese text from the registry. @hugleecool 's answer solves the problem. – Interarticle Jan 26 '14 at 02:32
  • Try [changing the cmd.exe terminal to UTF-8 did the job][1] [1]: https://stackoverflow.com/questions/388490/how-to-use-unicode-characters-in-windows-command-line/388500#388500 – José May 22 '18 at 21:58

5 Answers5

17

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!

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.

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:

if sys.getdefaultencoding() != 'gbk':
    reload(sys)
    sys.setdefaultencoding('gbk')
    default_encoding = sys.getdefaultencoding()
sega_sai
  • 8,328
  • 1
  • 29
  • 38
hugleecool
  • 205
  • 2
  • 9
  • 1
    There is another way, just pass UnicodeError exception instead of passing only UnicodeEncodeError for ctype = ctype.encode(default_encoding) in $Python/Lib/mimetypes.py:249 – http8086 Sep 24 '14 at 08:08
16

Try installing first libevent-devel and python-devel

yum install libevent-devel python-devel

and then installing

pip install uwsgi
leela
  • 555
  • 4
  • 11
4

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

sudo apt-get install build-essential
TheDimLebowski
  • 344
  • 1
  • 3
  • 12
4

Check that you have installed python-dev

sinθ
  • 11,093
  • 25
  • 85
  • 121
Lordn__n
  • 328
  • 2
  • 11
0

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.

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.

Yang_2333
  • 644
  • 8
  • 10