背景
pip打包:
setuptools
pip支持从wheel安装,卸载,依赖覆盖,列出已装的包,以及pep438过渡发布
而easy_install则支持egg安装,修改系统路径,多版本安装
egg 是一个包含所有包数据的文件包。在理想情况中,egg 是一个使用 zip 压缩的文件,其中包括了所有需要的包文件。但是在某些情况下,setuptools 会决定(或被开关告知)包不应该是 zip 压缩的。与 Java的 JAR文件 类似。
PyPA团队 开发的Python打包生态环境工具链: pip, setuptools, virtualenv 和 wheel.
wheel是用于替换egg格式,通过扩展setuptools,增加 bdist_wheel 功能就可以打包wheel文件。
pip可以直接安装wheel格式软件包,但无法安装egg格式软件包;如果需要安装egg格式,只能使用easy_install.
干货
1. yum install -y python-tools
2. install pip
$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ yum install -y python-pip
ref:http://sharadchhetri.com/2014/05/30/install-pip-centos-rhel-ubuntu-debian/
3. easy_install是由PEAK(Python Enterprise Application Kit)开发的setuptools包里带的一个命令,它用来安装egg包。egg包是目前最流行的python应用打包部署方式。
$ yum install -y python-setuptools
4. install supervisor
ref:http://supervisord.org/installing.html
5. pip install pypiserver
升级python
$ yum install -y centos-release-SCL
$ yum install -y python27
ref:https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only
6.启动服务:
target_dir=/data/jenkins-slave/workspace/pip_repository_deploy
${target_dir}/scripts/start_supervisor.sh
7.停止服务
target_dir=/data/jenkins-slave/workspace/pip_repository_deploy
${target_dir}/scripts/stop_supervisor.sh
upload them remotely with a python setup.py upload command. Currently only password-protected uploads are supported!
pip install passlib
可能会碰到找不到htpasswd程序,执行这个化解:
yum install -y httpd
安装http服务
htpasswd -sc htpasswd.txt public
输入密钥: xxx
然后在工作机器的家目录创建一个.pypirc
内容如下:
[distutils]
index-servers =
privatepypi
[privatepypi]
repository:http://pypi.python.cm:3141
username:public
password:xxx
怎么样使得包里面包含一个数据文件夹:
setup.py其实是python工具包distutils的配置文件,setuptools就是基于distutils来做的。 在setup.py中通过setup函数来配置打包信息。
from setuptools import setup, find_packages
setup(name='hello_pypi',
version='1.0',
py_modules=['hello_pypi'],
url='http://pypi.python.cm/packages/hello_pypi-1.0.tar.gz',
author='tangchen',
author_email='tangchen2008@gmail.com',
#packages=find_packages('utils'), #package to utils dir
#package_dir={'':'utils'},
include_package_data=True,
)
有些 python application 会依赖一些非 *.py 数据文件,比如 image, documentation 和 data tables 等,我们把这些文件统称为 data file,所以打包时需将这些文件包含在内。现在往 packagedemo 添加 data 目录和相关文件,在MANIFEST.in中include进来。
关键在"include_package_data=True,"
并且打包目录创建一个MANIFEST.in,内容如下
include data/*
然后执行:
python setup.py sdist
这样打好的包里面就包含相应的文件了
refer:
https://yijingping.github.io/2013/07/25/setting-up-your-own-pypi-server.html
http://stackoverflow.com/questions/18828805/how-can-i-install-packages-hosted-in-a-private-pypi-using-setup-py
http://lingxiankong.github.io/blog/2013/12/23/python-setup/