mac 下執(zhí)行pip報(bào)錯(cuò)TypeError

在終端輸入任何pip 相關(guān)的任何命令都會(huì)報(bào)錯(cuò):

File "/usr/local/bin/pip", line 11, in <module>
    load_entry_point('pip==10.0.1', 'console_scripts', 'pip')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2434, in load
    return self.resolve()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2440, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip/_internal/__init__.py", line 42, in <module>
    from pip._internal import cmdoptions
  File "/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip/_internal/cmdoptions.py", line 16, in <module>
    from pip._internal.index import (
  File "/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip/_internal/index.py", line 15, in <module>
    from pip._vendor import html5lib, requests, six
  File "/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip/_vendor/requests/__init__.py", line 86, in <module>
    from pip._vendor.urllib3.contrib import pyopenssl
  File "/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL/crypto.py", line 12, in <module>
    from cryptography import x509
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/x509/__init__.py", line 8, in <module>
    from cryptography.x509.base import (
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/x509/base.py", line 16, in <module>
    from cryptography.x509.extensions import Extension, ExtensionType
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/x509/extensions.py", line 24, in <module>
    from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/x509/general_name.py", line 16, in <module>
    from cryptography.x509.name import Name
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/x509/name.py", line 28, in <module>
    _ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
TypeError: 'type' object is not iterable

資料方案

  1. 方法1
    查找資料說可以如下解決:
sudo pip uninstall enum
sudo pip install enum34

但是該命令仍然會(huì)報(bào)上述錯(cuò)誤。

  1. 資料2
    手動(dòng)移除
  • Removed enum from "/usr/lib/python2.7/dist-packages": rm -rf enum*
  • When I tried to install enum34 using "pip install enum34" I still run into the same error from cryptography: "TypeError: 'type' object is not iterable". (I think its because there is a copy of enum present under "/usr/local/lib/python2.7/dist-packages" as well.
  • Next I removed cryptography from "/usr/lib/python2.7/dist-packages": rm -rf cryptography*
  • Now try running "pip uninstall enum", it works.
  • Then install enum34: pip install enum34
  • Then install cryptography again: pip install cryptography

最終解決

  • command + space按鍵打開搜索欄,輸入/library打開資源庫(kù)
  • 進(jìn)入/Library/Python/2.7目錄中發(fā)現(xiàn)只有site-packages目錄,且里面有enum相關(guān)的文件,應(yīng)該是之前自己通過pip install enum命令添加的
  • 輸入sudo rm -rf enum*
  • 安裝enum,pip install enum34

參考

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容