Skip to content

UnicodeDecodeError when install in Windows 7 #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Dec 29, 2013 · 14 comments
Closed

UnicodeDecodeError when install in Windows 7 #127

ghost opened this issue Dec 29, 2013 · 14 comments

Comments

@ghost
Copy link

ghost commented Dec 29, 2013

Originally reported by: tkdchen (Bitbucket: tkdchen, GitHub: tkdchen)


Install version 2.0.1 in Windows 7, Python 2.7.6 64bit. This error happened again when installing by running ez_setup.py downloaded from this repo.

#!python

Extracting in c:\users\chen\appdata\local\temp\tmprpne9d
Now working in c:\users\chen\appdata\local\temp\tmprpne9d\setuptools-2.0.1
Installing Setuptools
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    exec(init_file.read(), command_ns)
  File "<string>", line 8, in <module>
  File "c:\users\chen\appdata\local\temp\tmprpne9d\setuptools-2.0.1\setuptools\__init__.py", line 11, in <module>
    from setuptools.extension import Extension
  File "c:\users\chen\appdata\local\temp\tmprpne9d\setuptools-2.0.1\setuptools\extension.py", line 5, in <module>
    from setuptools.dist import _get_unpatched
  File "c:\users\chen\appdata\local\temp\tmprpne9d\setuptools-2.0.1\setuptools\dist.py", line 15, in <module>
    from setuptools.compat import numeric_types, basestring
  File "c:\users\chen\appdata\local\temp\tmprpne9d\setuptools-2.0.1\setuptools\compat.py", line 19, in <module>
    from SimpleHTTPServer import SimpleHTTPRequestHandler
  File "c:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
    class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  File "c:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHandler
    mimetypes.init() # try to read system mime.types
  File "c:\Python27\lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "c:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "c:\Python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
Something went wrong during the installation.
See the error message above.

@ghost
Copy link
Author

ghost commented Dec 29, 2013

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Based on the traceback, it looks like there's an error in your environment that's preventing mimetypes from initializing. I suspect if you do this:

python -c "import mimetypes; mimetypes.init()"

you will get the same traceback. Indeed, this bug has been reported upstream.

@ghost
Copy link
Author

ghost commented Dec 29, 2013

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


This bug applies to Python, not setuptools.

@ghost
Copy link
Author

ghost commented Dec 30, 2013

Original comment by tkdchen (Bitbucket: tkdchen, GitHub: tkdchen):


Thanks for that information. :)

@ghost
Copy link
Author

ghost commented Jan 8, 2014

Original comment by hugleecool (Bitbucket: hugleecool, GitHub: hugleecool):


HELLO! I come here by Google. I notice that the asker is a Chinese, the same to me. So, maybe we face the same problem. Then I register this website.
Oh, sorry for my bad English!

I HAVE FIND THE RIGHT ANSWER!

It is because when Python install 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()

简单来说,就是有些国内软件修改注册表导致python无法安装库,要改下lib目录下的代码。

@ghost
Copy link
Author

ghost commented Feb 8, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Issue #146 was marked as a duplicate of this issue.

@ghost
Copy link
Author

ghost commented Feb 8, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Issue #147 was marked as a duplicate of this issue.

@ghost
Copy link
Author

ghost commented Feb 8, 2014

Original comment by captals (Bitbucket: captals, GitHub: captals):


Thanks to hugleecool!I resolve the problem.

@ghost
Copy link
Author

ghost commented Feb 11, 2014

Original comment by atuxp (Bitbucket: atuxp, GitHub: atuxp):


多谢hugleecool,帮了大忙

@ghost
Copy link
Author

ghost commented Feb 17, 2014

Original comment by marco_chan (Bitbucket: marco_chan, GitHub: Unknown):


I got error when adding the line :
if sys.getdefaultencoding() != 'gbk': reload(sys) sys.setdefaultencoding('gbk')
to mimetypes.py

Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\mimetypes.py", line 256
reload(sys) sys.setdefaultencoding('gbk')
^
SyntaxError: invalid syntax

I am newbie, pls help

@ghost
Copy link
Author

ghost commented Feb 17, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


marco_chan: you need for the code to be proper Python syntax:

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

@ghost
Copy link
Author

ghost commented Feb 18, 2014

Original comment by marco_chan (Bitbucket: marco_chan, GitHub: Unknown):


Thanks Jason! My PC is traditional Chinese, whre gbk is simplified Chinese.

To share with other people using traditional, the codes needed will be:

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

@ghost
Copy link
Author

ghost commented Mar 15, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Issue #166 was marked as a duplicate of this issue.

@ghost
Copy link
Author

ghost commented Apr 15, 2014

Original comment by erickmendonca (Bitbucket: erickmendonca, GitHub: erickmendonca):


I'm Brazilian and found the same issue on my system. The workaround fixed it for now. Thanks.

@ghost
Copy link
Author

ghost commented Sep 9, 2014

Original comment by athruncole (Bitbucket: athruncole, GitHub: Unknown):


Thanks to hugleecool !!!!! you so cool!!!!!

@ghost ghost added major bug labels Mar 29, 2016
@ghost ghost closed this as completed Mar 29, 2016
jaraco added a commit that referenced this issue Mar 19, 2022
Pass through PROGRAMDATA, PROGRAMFILES env variables
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants