解決pycharm問題: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)
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM