搭建私有的PyPI仓库源

来源:互联网 发布:淘宝售后客服消差评 编辑:程序博客网 时间:2024/06/15 04:58

1.官方PyPI源以及私有PyPI

  通常我们使用pip安装python包,都会默认从https://pypi.python.org/pypi上安装,非常方便。但是有些是公司内部的项目,不方便放到外网上去,这个时候我们就要搭建自己的内网pypi源服务器,需要安全并且拥有同样的舒适体验。所以我们有些公司中,就需要搭建自己的PyPI仓库,Python官方有个pypi私有源实现的说明(http://wiki.python.org/moin/PyPiImplementations),并且列出了几个比较成熟的实现方案:

(1)PyPI , aka CheeseShop - The reference implementation, powering themain index.(2)ClueReleaseManager(3)EggBasket - A simple, lightweight Python Package Index (akaCheeseshop) clone.(4)haufe.eggserver - Grok-based local repository with upload and nosecurity model.(4)Plone Software Center(5)chishop - django based(6)pypiserver - minimal pypi server, easy to install & use

一般来说,使用pypiserver比较简单一些,因为他最小而且使用简单。

 

2.往官方PyPI或私有PyPI中上传Python

  使用setup.py上传python模块时,会使用setup.py脚本的register/upload的命令,但是registerupload命令会去~/.pypirc配置文件中,查找PyPI的配置。如果是搭建了一个私有PyPI源,那么就需要在~/.pypirc中配置下私有仓库的地址,账号和密码信息。实例如下:

index-servers = pypi pypitesttest-pypi #官方PyPI源信息[pypi]repository: https://pypi.python.org/pypi username:{{your_username}} password:{{your_password}}  #官方测试PyPI源信息[pypitest]repository: https://testpypi.python.org/pypi username:{{your_username}} password:{{your_password}}  #自己搭建的PyPI源信息[test-pypi]repository:https://127.0.0.1/pypi username:{{your_username}} password:{{your_password}}

发布时,可以指定往哪个PyPI仓库发布,例如向test-pypi发布的命令如下:

python setup.py register -r test-pypipython setup.py sdist upload -r test-pypi

3.pip配置指定PyPI

pip默认是从官方PyPI源仓库中下载和安装包。其实这个可以配置一个指定的PyPI源,配置文件是~/.pip/pip.conf,例如需要从豆瓣pip源中下载,配置如下:

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


0 0
原创粉丝点击