win7下 pip install package 报错解决办法

首先我的python版本是3.7.0,运行代码是报告:没有办法用库文件,按照网上的方法在python安装目录下pip install XXX也不行

网上找了很多方法,最后读到这一篇文章:(按操作已解决问题^ ^)

更新之后,在D:\Python27目录下并没有Scripts这个文件夹,什么鬼!没有就没有吧,那我来手动安装pip,具体过程不说了,balabala,装好了,输入pip -V可用,运行pip install package,结果如图:我是图 
解决办法,打开D:\Python27\lib\mimetypes.py文件,在254行附近加入两行代码修改如下:

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    if '\0' in subkeyname: # new
                        continue # new
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises EnvironmentError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        try:
                            mimetype = mimetype.encode(default_encoding)
                        except UnicodeEncodeError:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except EnvironmentError:
                    continue
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

这样再使用pip的时候就不会有问题了,这个问题实际上是因为HKEY_CLASSES_ROOT损坏的注册表项导致的,这可能是一个很好的解决方案,如果你不希望修改注册表的话,这个问题在python3.4版本中也可能存在。

猜你喜欢

转载自blog.csdn.net/simpleshao/article/details/79261864