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

在pycharm上面遇到了坑记下来,帮大家填坑

找到安装目录下 helpers/packaging_tool.py文件,找到如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)

改为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

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)

转载自:http://www.cnblogs.com/Fordestiny/p/8901100.html

-------------本文结束感谢您的阅读-------------
如有疑问或需要技术讨论,请发邮件到 zlem0n@foxmail.com