解决AttributeError: 'module' object has no attribute 'main' 安装第三方包报错
import sysimport tracebackimport getoptimport osERROR_WRONG_USAGE = 1ERROR_NO_PIP = 2ERROR_NO_SETUPTOOLS = 3ERROR_EXCEPTION = 4os.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 0def 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 Nonedef 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' 安装第三方包报错的更多相关文章
- 安装pandas报错(AttributeError: 'module' object has no attribute 'main')
在pycharm中安装pandas出现报错:AttributeError: 'module' object has no attribute 'main', 刚开始以为是pip的版本太旧了,于是乎将其 ...
- AttributeError: 'module' object has no attribute 'main'
本机环境:ubuntu16.04, ros-kinetic $ roscore 报错 Traceback (most recent call last): File , in <module& ...
- 【Python】【亲测好用】安装第三方包报错:AttributeError:'module' object has no attribute 'main'
安装/卸载第三包可能出现如下问题及相应解决办法: 在pycharm编辑中,使用anconda2更新.卸载第三方包时,出现如下错误: AttributeError:'module' object has ...
- window7下安装第三方包报错及解决
window7 64位下安装第三方包,,比如安装yaml的exe执行文件,会 报错及解决:python version 2.7(3.4) required,which was not found in ...
- 解决 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 后,无法 ...
- pycharm 安装第三方库报错:AttributeError: 'module' object has no attribute 'main'
pip升级到 10.0.1 之后 老版的pycharm 使用pip安装第三方库的时候会报错,报错如上图所示: 其主要原因是 新版的 pip 更改了 部分api 将其中 pip.main() 改为 pi ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法
pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...
- 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'
利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...
随机推荐
- hdu 2089 数位dp入门题
#include<stdio.h> //dp[i][0]代表不存在不吉利数字 //dp[i][1]代表不存在不吉利数字但是以2开头 //dp[i][2]代表存在不吉利数字 #define ...
- HDU 4535
裸 的错排.... #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- Lua5.2 请求 luasocket 相关模块时的 multiple-lua-vms-detected
首先说一下5.3貌似没有这个问题, 可是眼下最新版的luasocket 3.0 rc1仅仅能支持5.2, 5.3调用的话程序会崩溃(不知道是不是我没配置好) 出现这个问题的解决办法, 想必网上有非常多 ...
- JVM基础(二) 实现自己的ClassLoader
为何要花时间实现自己的ClassLoader 尽管人生的乐趣非常大一部分来自于将时间花在有意思可是无意义的事情上,可是这件事绝对是有意思并且有意义的,有下面几个情景是值得我们花费时间实现自己的clas ...
- 拒绝switch,程序加速之函数指针数组
先看一个使用switch语句的程序: #include <stdio.h> #include <time.h> //加法 int add(int a,int b) { retu ...
- Chrome Extension 的 webRequest模块的解读
Chrome Extension 的 webRequest模块的解读 文档在此:http://developer.chrome.com/trunk/extensions/webRequest.ht ...
- hdu 5411 CRB and Puzzle 矩阵高速幂
链接 题解链接:http://www.cygmasot.com/index.php/2015/08/20/hdu_5411/ 给定n个点 常数m 以下n行第i行第一个数字表示i点的出边数.后面给出这些 ...
- 【视频】零基础学Android开发:蓝牙聊天室APP(一)
零基础学Android开发:蓝牙聊天室APP第一讲 1. Android介绍与环境搭建:史上最高效Android入门学习 1.1 Google的大小战略 1.2 物联网与云计算 1.3 智能XX设备 ...
- Centos7操作系统部署指南
一.硬件环境: Dell R620 二.软件环境: Centos6.4 X86_64 +KVM Windows7+vnc 三.安装说明 操作系统更新之迅速,让作为新手的系统运维人员有点措手不及,相对于 ...
- DNS tunnel的原理及实战
DNS tunnel的原理及实战 摘自:http://netsec.ccert.edu.cn/zhengming/2011/11/01/%E8%BD%AC%E8%BD%BD%EF%BC%9Adns-t ...