Pycharm 报错 AttributeError: module 'pip' has no attribute 'main'

时间:2022-05-12 16:41:23

1.打开文件packaging_tool.py:

  D:\Program files\pycharm\PyCharm 2016.3.2\helpers\packaging_tool.py

2.添加导入:

  import pip._internal as pip_new

3.修改参数

  修改前的代码为:  

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
except ImportError:
error_no_pip()
return pip_new.main(['install'] + pkgs) def do_uninstall(pkgs):
try:
import pip
except ImportError:
error_no_pip()
return pip_new.main(['uninstall', '-y'] + pkgs)