module 'pip' has no attribute 'main'

时间:2022-01-17 15:46:13

摘录自:http://www.cnblogs.com/Fordestiny/p/8901100.html

问题分析:

  module 'pip' has no attribute 'main'

问题解决:

   找到安装目录下 helpers/packaging_tool.py文件

   module 'pip' has no attribute 'main'

找到如下代码:
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)