Python 使用PIP安装程序包时出现Mimetypes.init()错误

Python 使用PIP安装程序包时出现Mimetypes.init()错误,python,pip,mime-types,Python,Pip,Mime Types,编辑:通过打开C:\Python27\Lib\mimetypes.py并将代码下方添加到try块来解决问题: 我从3天前开始搜索,但解决这个问题对我来说太难了。我不明白问题出在哪里 我尝试使用GitHub、PowerShell 3等安装我的软件包。所有这些都不起作用。除了皮普·威奇似乎有点小毛病 当我尝试使用PIP安装tweepy时,此错误会附加: Microsoft Windows [version 6.2.9200] (c) 2012 Microsoft Corporation. Tous

编辑:通过打开C:\Python27\Lib\mimetypes.py并将代码下方添加到try块来解决问题:

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

我尝试使用GitHub、PowerShell 3等安装我的软件包。所有这些都不起作用。除了皮普·威奇似乎有点小毛病

当我尝试使用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。

看起来您的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行中添加一个通用类型,与我上面所做的类似。

更改第250行

except (UnicodeEncodeError, UnicodeDecodeError):
    pass

pip-version打印出什么,C:\Users\user\pip\pip.log说什么?pip-version什么都不做,它说找不到程序。日志文件在这里:当您调用它来安装C:\Users\user>pip install tweepy时,pip-version怎么能什么都不做呢..因为由于错误,pip没有安装你很困惑。pip是用来安装tweepy的。我可以看到pip正在运行,因为当您运行pip install tweepy时,您会得到输出。这运行pip告诉它安装tweepy包。运行pip install tweepy的方式与运行pip-version的方式有什么区别?我在运行脚本时没有任何错误,所有的模拟类型都正常。ps:您忘了导入系统^^
except (UnicodeEncodeError, UnicodeDecodeError):
    pass