Python3的pip从版本8升级到版本10之后,在Pycharm中安装package,会出现如下问题:
AttributeError: module ‘pip’ has no attribute ‘main’
解决方案如下:
找到安装目录下的helpers/packaging_tool.py文件,将如下代码1
2
3
4
5
6
7
8
9
10
11
12
13def 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
22def 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
import pip
except ImportError:
error_no_pip()
return main(['uninstall', '-y'] + pkgs)