问题:
在电脑终端安装了pyquery且能正常导入,但在pycharm中不能导入,提示没有该模块。在pycharm setting中安装出现如下错误:
AttributeError: module 'pip' has no attribute 'main'
错误原因:当前pip版本中没有main(),不降级的情况下解决办法如下:
找到pycharm安装目录下 helpers/packaging_tool.py文件,找到如下代码:
#从104行开始 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)
方法二:降级pip版本
python -m pip install --upgrade pip==9.0.3
来源:https://www.cnblogs.com/rong1111/p/12164663.html