1.找到pycharm 目录下的 \helper\packaging_tool.py 文件
2.用新版pycharm 的packaging_tool.py 替换 旧版 同名文件
文件代码如下:
import sys
import traceback
import getopt
import os
 
ERROR_WRONG_USAGE = 1
ERROR_NO_PIP = 2
ERROR_NO_SETUPTOOLS = 3
ERROR_EXCEPTION = 4
 
os.putenv("PIP_REQUIRE_VIRTUALENV", "false")
 
def exit(retcode):
    major, minor, micro, release, serial = sys.version_info
    version = major * 10 + minor
    if version < 25:
        import os
        os._exit(retcode)
    else:
        sys.exit(retcode)
 
 
def usage():
    sys.stderr.write('Usage: packaging_tool.py <list|install|uninstall|pyvenv>\n')
    sys.stderr.flush()
    exit(ERROR_WRONG_USAGE)
 
 
def error(message, retcode):
    sys.stderr.write('Error: %s\n' % message)
    sys.stderr.flush()
    exit(retcode)
 
 
def error_no_pip():
    type, value, tb = sys.exc_info()
    if tb is not None and tb.tb_next is None:
        error("Python packaging tool 'pip' not found", ERROR_NO_PIP)
    else:
        error(traceback.format_exc(), ERROR_EXCEPTION)
 
 
def do_list():
    try:
        import pkg_resources
    except ImportError:
        error("Python packaging tool 'setuptools' not found", ERROR_NO_SETUPTOOLS)
    for pkg in pkg_resources.working_set:
        try:
            requirements = pkg.requires()
        except Exception:
            requirements = []
        requires = ':'.join([str(x) for x in requirements])
        sys.stdout.write('\t'.join([pkg.project_name, pkg.version, pkg.location, requires])+chr(10))
    sys.stdout.flush()
 
 
def do_install(pkgs):  
    return pip_main(['install'] + pkgs)
 
 
def do_uninstall(pkgs):
    return pip_main(['uninstall', '-y'] + pkgs)
 
 
def pip_main(args):
    try:
        import pip
    except ImportError:
        error_no_pip()
 
    try:
        func = pip.main
    except AttributeError:
        from pip._internal import main as func
 
    func(args)
 
 
def do_pyvenv(path, system_site_packages):
    try:
        import venv
    except ImportError:
        error("Standard Python 'venv' module not found", ERROR_EXCEPTION)
    # In Python >= 3.4 venv.create() has a new parameter with_pip=False
    # that allows to automatically install setuptools and pip with the module
    # ensurepip. Unfortunately, we cannot use this parameter and have to
    # bootstrap these packages ourselves, since some distributions of CPython
    # on Ubuntu don't include ensurepip.
    venv.create(path, system_site_packages=system_site_packages)
 
 
def do_untar(name):
    import tempfile
 
    directory_name = tempfile.mkdtemp("pycharm-management")
 
    import tarfile
 
    tar = tarfile.open(name)
    for item in tar:
        tar.extract(item, directory_name)
 
    sys.stdout.write(directory_name+chr(10))
    sys.stdout.flush()
    return 0
 
 
def mkdtemp_ifneeded():
    try:
        ind = sys.argv.index('--build-dir')
        if not os.path.exists(sys.argv[ind + 1]):
            import tempfile
 
            sys.argv[ind + 1] = tempfile.mkdtemp('pycharm-packaging')
            return sys.argv[ind + 1]
    except:
        pass
 
    return None
 
 
def main():
    try:
        # As a workaround for #885 in setuptools, don't expose other helpers
        # in sys.path so as not no confuse it with possible combination of
        # namespace/ordinary packages
        sys.path.remove(os.path.dirname(__file__))
    except ValueError:
        pass
 
    retcode = 0
    try:
        if len(sys.argv) < 2:
            usage()
        cmd = sys.argv[1]
        if cmd == 'list':
            if len(sys.argv) != 2:
                usage()
            do_list()
        elif cmd == 'install':
            if len(sys.argv) < 2:
                usage()
 
            rmdir = mkdtemp_ifneeded()
 
            pkgs = sys.argv[2:]
            retcode = do_install(pkgs)
 
            if rmdir is not None:
                import shutil
                shutil.rmtree(rmdir)
 
 
        elif cmd == 'untar':
            if len(sys.argv) < 2:
                usage()
            name = sys.argv[2]
            retcode = do_untar(name)
        elif cmd == 'uninstall':
            if len(sys.argv) < 2:
                usage()
            pkgs = sys.argv[2:]
            retcode = do_uninstall(pkgs)
        elif cmd == 'pyvenv':
            opts, args = getopt.getopt(sys.argv[2:], '', ['system-site-packages'])
            if len(args) != 1:
                usage()
            path = args[0]
            system_site_packages = False
            for opt, arg in opts:
                if opt == '--system-site-packages':
                    system_site_packages = True
            do_pyvenv(path, system_site_packages)
        else:
            usage()
    except Exception:
        traceback.print_exc()
        exit(ERROR_EXCEPTION)
    exit(retcode)
 
if __name__ == '__main__':
    main()
 
替换掉代码即可

解决AttributeError: 'module' object has no attribute 'main' 安装第三方包报错的更多相关文章

  1. 安装pandas报错(AttributeError: 'module' object has no attribute 'main')

    在pycharm中安装pandas出现报错:AttributeError: 'module' object has no attribute 'main', 刚开始以为是pip的版本太旧了,于是乎将其 ...

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

    本机环境:ubuntu16.04,  ros-kinetic $ roscore 报错 Traceback (most recent call last): File , in <module& ...

  3. 【Python】【亲测好用】安装第三方包报错:AttributeError:'module' object has no attribute 'main'

    安装/卸载第三包可能出现如下问题及相应解决办法: 在pycharm编辑中,使用anconda2更新.卸载第三方包时,出现如下错误: AttributeError:'module' object has ...

  4. window7下安装第三方包报错及解决

    window7 64位下安装第三方包,,比如安装yaml的exe执行文件,会 报错及解决:python version 2.7(3.4) required,which was not found in ...

  5. 解决 mac 10.14.4 无法 sublime text 3207 安装 Package Control,以及安装第三方包报错 `Package Control There are no packages available for installation`

    下载最新的 sublime text 3207,无法安装 Package Control. 根据官方提示,手动安装 Package Control. 手动安装 Package Control 后,无法 ...

  6. pycharm 安装第三方库报错:AttributeError: 'module' object has no attribute 'main'

    pip升级到 10.0.1 之后 老版的pycharm 使用pip安装第三方库的时候会报错,报错如上图所示: 其主要原因是 新版的 pip 更改了 部分api 将其中 pip.main() 改为 pi ...

  7. attributeError:'module' object has no attribute ** 解决办法

    写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...

  8. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  9. 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'

    利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...

随机推荐

  1. UOJ #131 BZOJ 4199 luogu P2178【NOI2015】品酒大会 (后缀自动机、树形DP)

    水是水,但是写出了不少问题,因此写一发博客. https://www.luogu.org/problemnew/show/P2178 https://www.lydsy.com/JudgeOnline ...

  2. HDU 2795 Billboard (线段树+贪心)

    手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...

  3. 读取com口接收byte数据的处理

    procedure Tfrm_CheckCloth.cnrs232ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); ...

  4. Java路径获取

    package unit02; /** * * @time 2014年9月18日 下午10:29:48 * @porject ThinkingInJava * @author Kiwi */ publ ...

  5. C算法与数据结构-线性表的应用,多项式求和---ShinePans

    /*---上机作业作业,二项式加法---*/ /*---By 潘尚 ---*/ /*---日期: 2014-5-8 . ---*/ /*---题目:---*/ //如果有两个稀疏多项式A和B,设计算法 ...

  6. 准备开源用javascript写Tomcat下的WebApp的项目

    原创文章,转载请注明. 这个想法由来已久.用javascript编写Tomcat下的WebApp.现现在也有alpha版本号的实现. 这种话,前端程序猿就能够像用Node.js那样,用javascri ...

  7. 问题2-:Syntax error on tokens, delete these tokens

    出现原因:拷贝下来的代码缺少{左大括号 然后运行时run as 没有选到java application 是因为没有main方法 加个public static void main(String() ...

  8. Oracle 10G 中的"回收站"

    在Oracle 10g数据库中,引入了一个回收站(Recycle Bin)的数据库对象. 回收站,从原理上来说就是一个数据字典表,放置用户Drop掉的数据库对象信息.用户进行Drop操作的对象并没有被 ...

  9. 【NOIP 2004】 虫食算

    [题目链接] https://www.luogu.org/problemnew/show/P1092 [算法] 搜索 + 剪枝 直接搜索显然会超时,考虑剪枝 1 : 优化搜索顺序 2 : 假设我们已经 ...

  10. 【POJ 3071】 Football

    [题目链接] http://poj.org/problem?id=3071 [算法] 概率DP f[i][j]表示第j支队伍进入第i轮的概率,转移比较显然 [代码] #include <algo ...