AttributeError: 'module' object has no attribute 'main'

简介: AttributeError: 'module' object has no attribute 'main'

pycharm 安装 flask 时候报错


pycharm版本:2017.2.3
python版本:2.7
pip版本:10.0.1

报错

image.png


Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py", line 192, in main
    retcode = do_install(pkgs)
  File "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py", line 109, in do_install
    return pip.main(['install'] + pkgs)
AttributeError: 'module' object has no attribute 'main'

原因

新版pip中的main函数已经发生了变化,是pycharm的原因


参考:

PyCharm 2017.3 在pip10.0.0版本中报错(module ‘pip’ has no attribute ‘main’)


解决

方式一


通过 pip 命令手动安装

方式二

根据报错提示中的路径


 

"/Applications/PyCharm.app/Contents/helpers/packaging_tool.py"

打开文件,如果在mac中找不到文件,可以使用打开


$ vim "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py"

打开后找到如下代码


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:
        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)

问题成功解决


相关文章
|
2月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
50 0
|
12天前
|
Python
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
6 0
|
2月前
|
机器学习/深度学习 监控 数据可视化
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
【已解决】 ‘Conv2d’ object has no attribute ‘register_full_backward_hook’
|
2月前
|
安全 计算机视觉 Python
【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘
【已解决】attributeerror: ‘FreeTypeFont‘ object has no attribute ‘getsize‘
|
2月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
412 0
|
2月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
154 0
|
2月前
|
Java
Java Object 类
5月更文挑战第16天
|
2月前
|
存储 算法 Java
滚雪球学Java(42):探索对象的奥秘:解析Java中的Object类
【5月更文挑战第17天】🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!!
28 2
滚雪球学Java(42):探索对象的奥秘:解析Java中的Object类
|
13天前
|
Java
【Java】Object类简单解析
【Java】Object类简单解析
15 1
|
18天前
|
前端开发 JavaScript Java
Java基础10-深入理解Class类和Object类(二)
Java基础10-深入理解Class类和Object类(二)
21 5