问题描述:
安装第三方包的时候遇到的 AttributeError: module ‘pip’ has no attribute ‘main’
找到安装目录下 helpers/packaging_tool.py文件,找到如下代码:
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)
建议直接删除了,粘贴最下面的代码过去,省的遇到各种缩进问题。
这里改了两个地方
try:
from pip._internal import main
except Exception:
from pip import main
return 的东西也改了
return main(['install'] + 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)
重新安装结果: