windos自动下载setuptools的Python脚本

这是一个Python脚本,用于自动下载和安装setuptools。脚本首先警告使用ez_setup.py是过时的,并提供了弃用原因。然后,它从指定URL下载setuptools的指定版本,解压缩文件,构建并安装setuptools的egg。该脚本适用于Python 2.6及更高版本,并在没有pkg_resources冲突的情况下执行安装。
摘要由CSDN通过智能技术生成
#!/usr/bin/env python


"""
Setuptools bootstrapping installer.


Maintained at https://github.com/pypa/setuptools/tree/bootstrap.


Run this script to install or upgrade setuptools.


This method is DEPRECATED. Check https://github.com/pypa/setuptools/issues/581 for more details.
"""


import os
import shutil
import sys
import tempfile
import zipfile
import optparse
import subprocess
import platform
import textwrap
import contextlib


from distutils import log


try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen


try:
    from site import USER_SITE
except ImportError:
    USER_SITE = None


# 33.1.1 is the last version that supports setuptools self upgrade/installation.
DEFAULT_VERSION = "33.1.1"
DEFAULT_URL = "https://pypi.io/packages/source/s/setuptools/"
DEFAULT_SAVE_DIR = os.curdir
DEFAULT_DEPRECATION_MESSAGE = "ez_setup.py is deprecated and when using it setuptools will be pinned to {0} since it's the last version that supports setuptools self upgrade/installation, check https://github.com/pypa/setuptools/issues/581 for more info; use pip to install setuptools"


MEANINGFUL_INVALID_ZIP_ERR_MSG = 'Maybe {0} is corrupted, delete it and try again.'


log.warn(DEFAULT_DEPRECATION_MESSAGE.format(DEFAULT_VERSION))




def _python_cmd(*args):
    """
    Execute a command.


    Return True if the command succeeded.
    """
    args = (sys.executable,) + args
    return subprocess.call(args) == 0




def _install(archive_filename, install_args=()):
    """Install Setuptools."""
    with archive_context(archive_filename):
        # installing
        log.warn('Installing Setuptools')
        if not _python_cmd('setup.py', 'install', *install_args):
            log.warn('Something went wrong during the installation.')
            log.warn('See the error message above.')
            # exitcode will be 2
            return 2




def _build_egg(egg, archive_filename, to_dir):
    """Build Setuptools egg."""
    with archive_context(archive_filename):
        # building an egg
        log.warn('Building a Setuptools egg in %s', to_dir)
        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
    # returning the result
    log.warn(egg)
    if not os.path.exists(egg):
        raise IOError('Could not build the egg.')




class ContextualZipFile(zipfile.ZipFile):


    """Supplement ZipFile class to support context manager for Python 2.6."""


    def __enter__(self):
        ret
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值