解决PyCharm安装package问题

使用PyCharm安装package出现:AttributeError: module 'pip' has no attribute 'main'

原因是:pip更新

修改PyCharm安装目录下:helpers/packaging_tool.py,找到代码:

修改为:

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

Ctrl+S 保存
再次用PyCharm安装package即可
若再次安装出现问题:NameError: name 'pip' is not defined

则是上面修改的两个函数的返回值错误,下图红色处删除pip.就ok了

 

猜你喜欢

转载自www.cnblogs.com/chenjing-jing/p/9105220.html