解决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 ...
随机推荐
- CentOS 6.3(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...
- 洛谷 P2144 BZOJ 1003 [FJOI2007]轮状病毒
题目描述 轮状病毒有很多变种.许多轮状病毒都是由一个轮状基产生.一个n轮状基由圆环上n个不同的基原子和圆心的一个核原子构成.2个原子之间的边表示这2个原子之间的信息通道,如图1. n轮状病毒的产生规律 ...
- SCU - 4110 - PE class
先上题目: 4110: PE class Submit your solution Discuss this problem Best solutions Description ...
- 【ACM】hdu_zs3_1005_String Matching_201308100920
String Matching Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)Tota ...
- [bzoj5118]Fib数列2_费马小定理_矩阵乘法
Fib数列2 bzoj-5118 题目大意:求Fib($2^n$). 注释:$1\le n\le 10^{15}$. 想法:开始一看觉得一定是道神题,多好的题面啊?结果...妈的,模数是质数,费马小定 ...
- CodeForces - 344A Magnets (模拟题)
CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...
- 【cl】Red Hat Linux虚拟机安装Vmware Tools
1.选择虚拟机,选中导航栏虚拟机>VMware Tool安装 选择右键>extract to 选择/home,新建了自己的文件夹,然后点击extract 一直enter,一直到 然后reb ...
- 安装visual studio 2013--【转】
本文转载自:http://blog.csdn.net/tina_ttl/article/details/51544733#1下载-visual-studio-ultimate-2013安装包 1.下载 ...
- Java Colections 集合类 —— List、ArrayList、Set(HashSet)
0. List<T> 是一个接口 该接口定义的高级成员函数有: contains() ⇒ 是否包含: String[] people; List names = Arrays.asList ...
- Java中利用随机数的猜拳游戏
Java中利用随机数的猜拳游戏,实现非常简单,重难点在于随机数的产生. 首先GameJude类是用于判断输赢的一个类: package testGame; public class GameJudge ...