使用PIP安装软件包时出现Mimetypes.init()错误

时间:2014-09-23 16:47:15

标签: python pip mime-types

编辑:打开C:\ Python27 \ Lib \ mimetypes.py并在try块中添加代码缺点解决了问题:

## Begin to line 245 :    
try:
    ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
    break
try:
    ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
    pass

## Here, add the universal Exception missing.
except Exception:
    pass

else:
    yield ctype

我在3天前搜索,但解决这个问题对我来说太难了。我不明白问题出在哪里。

我尝试使用GitHub,PowerShell 3等安装我的软件包。所有这些都无法正常工作。除了PIP,似乎有一点小错误......

当我尝试使用PIP安装 tweepy 时,会出现此错误:

Microsoft Windows [version 6.2.9200]
(c) 2012 Microsoft Corporation. Tous droits réservés.

C:\Users\user>pip install tweepy
Downloading/unpacking tweepy
  Downloading tweepy-2.3.0.tar.gz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run

    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
  File "C:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
    req_to_install.run_egg_info()
  File "C:\Python27\lib\site-packages\pip\req.py", line 292, in run_egg_info
    logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.s
etup_py, self.name))
  File "C:\Python27\lib\site-packages\pip\req.py", line 265, in setup_py
    import setuptools
  File "C:\Python27\lib\site-packages\setuptools\__init__.py", line 12, in <modu
le>
    from setuptools.extension import Extension
  File "C:\Python27\lib\site-packages\setuptools\extension.py", line 7, in <modu
le>
    from setuptools.dist import _get_unpatched
  File "C:\Python27\lib\site-packages\setuptools\dist.py", line 16, in <module>
    from setuptools.depends import Require
  File "C:\Python27\lib\site-packages\setuptools\depends.py", line 6, in <module
>
    from setuptools import compat
  File "C:\Python27\lib\site-packages\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 SimpleHTTPRequestHand
ler
    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 0xe9 in position 3: ordinal
not in range(128)

Storing debug log for failure in C:\Users\user\pip\pip.log

请你解释一下,如何重复这个?

提前致谢, SkyzohKey。

2 个答案:

答案 0 :(得分:0)

看起来你在Windows注册表中有一个导致问题的mimetype。您可以运行以下脚本来确定它是哪一个:

import _winreg


def find_funky_mimetype():
    default_encoding = sys.getdefaultencoding()
    with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
                         r'MIME\Database\Content Type') as mimedb:
        i = 0
        while 1:
            try:
                ctype = _winreg.EnumKey(mimedb, i)
            except EnvironmentError:
                break
            print 'testing:', `ctype`,
            try:
                ctype = ctype.encode(default_encoding) # omit in 3.x!
            except UnicodeEncodeError:
                print 'expected failure'
            except Exception as e:
                print 'unexpected failure:', e
            else:
                print 'ok.'
            i += 1


if __name__ == "__main__":
    find_funky_mimetype()

你应该做些什么完全取决于你和你感觉舒服的东西(例如从注册表中删除有问题的mimetype或添加一个通用,除了在`c:\ Python27 \ lib \ mimetypes.py的第252行外我上面所做的事情。)

答案 1 :(得分:0)

更改第250行

except (UnicodeEncodeError, UnicodeDecodeError):
    pass