AttributeError: module 'pip' has no attribute 'main'问题解决


 

Mac平台下找到packaging_tool.py(如果其他平台可以按报错查这个文件目录及文件。)

URL:/Applications/PyCharm.app/Contents/helpers/packaging_tool.py

 

好久没打开PyCharm创建项目了,今天打开突然报了一个“AttributeError: module 'pip' has no attribute 'main'”查了资料才知道怎么解决。

vim /Applications/PyCharm.app/Contents/helpers/packaging_tool.py

修改do_install和do_uninstall

原来:
def do_install(pkgs):
    try:
        import pip
    except ImportError:
        error_no_pip()
    return pip.main(['install'] + pkgs)


def do_uninstall(pkgs):
    try:
        import pip
    except ImportError:
        error_no_pip()
    return pip.main(['uninstall', '-y'] + pkgs)

修改后
def do_install(pkgs):
    try:
        #import pip try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main(['install'] + pkgs)


def do_uninstall(pkgs):
    try:
        #import pip try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main(['uninstall', '-y'] + pkgs)

修改好就OK了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM