PyPi镜像配置

简介

高墙内PyPi下载包时很慢,可以配置为国内镜像提速。

配置方式

PyPi镜像地址有多种配置方式

  • 系统全局配置 - /etc/pip.conf
  • 当前用户配置 - $HOME/.pip/pip.conf
  • 虚拟环境配置 - $VIRTUAL_ENV/pip.conf
  • 临时指定镜像 - pip install -i 镜像地址 包名

以上几种方式中,配置文件内容一样,如:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple

其他镜像

上例用了阿里云的镜像地址,除此,还有其他的镜像地址可选

即使配置了pip国内镜像,有些包安装过程中还是会卡住,因为自动装一些其他依赖时又会走python自带的源。

解决方法是修改./lib/python2.7/site-packages/setuptools/package_index.py:

搜索 PackageIndex,修改如下:

class PackageIndex(Environment):
    """A distribution index that scans web pages for download URLs"""

    def __init__(
            #self, index_url="https://pypi.org/simple/", hosts=('*',),
            self, index_url="http://mirrors.aliyun.com/pypi/simple", hosts=('*',),
            ca_bundle=None, verify_ssl=True, *args, **kw
    ):
        Environment.__init__(self, *args, **kw)
        index_url = "http://mirrors.aliyun.com/pypi/simple"
        self.index_url = index_url + "/" [:not index_url.endswith('/')]
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容