【转】发布python的包至pypi服务器

【原文链接】http://yejinxin.github.io/distribute-python-packages-to-pypi-server/

使用pip或easy_install可以管理和安装python的package包,实际上它们都是从pypi服务器中搜索和下载package的。目前在pypi服务器上,有超过三万多个package,同时还允许我们将自己的代码也上传发布到服务器上。这样,世界上的所有人都能使用pip或easy_install来下载使用我们的代码了。

具体步骤如下:

  • 首先创建项目文件和setup文件。

    目录文件结构如下:

    project/
        simpletest/
            __init__.py
            test.py
        setup.py
    

    假设项目文件只有一个simpletest包,里面有一个test.py文件。

    创建的setup.py文件格式大致如下,其中,install_requires字段可以列出依赖的包信息,用户使用pip或easy_install安装时会自动下载依赖的包。详细的格式参考文档

    from setuptools import setup, find_packages
    
    setup(
        name = 'simpletest',
        version = '0.0.1',
        keywords = ('simple', 'test'),
        description = 'just a simple test',
        license = 'MIT License',
        install_requires = ['simplejson>=1.1'],
    
        author = 'yjx',
        author_email = 'not@all.com',
        
        packages = find_packages(),
        platforms = 'any',
    )
    
  • 然后将代码打包。

    打包只需要执行python setup.py xxx命令即可,其中xxx是打包格式的选项,如下:

    # 以下所有生成文件将在当前路径下 dist 目录中
    python setup.py bdist_egg # 生成easy_install支持的格式 
    python setup.py sdist     # 生成pip支持的格式,下文以此为例
    
  • 发布到pypi。

    发布到pypi首先需要注册一个账号,然后进行如下两步:

    1. 注册package。输入python setup.py register
    2. 上传文件。输入python setup.py sdist upload
  • 安装测试

    上传成功后,就可以使用pip来下载安装了。

    另外,pypi还有一个测试服务器,可以在这个测试服务器上做测试,测试的时候需要给命令指定额外的"-r"或"-i"选项,如python setup.py register -r "https://testpypi.python.org/pypi",python setup.py sdist upload -r "https://testpypi.python.org/pypi",pip install -i "https://testpypi.python.org/pypi" simpletest

    发布到测试服务器的时候,建议在linux或cygwin中发布,如果是在windows中,参考文档,需要生成.pypirc文件,参考另一篇博文

reference

http://liluo.org/blog/2012/08/how-to-create-python-egg/

http://blog.jkey.lu/2013/04/11/create-python-egg/

http://docs.python.org/2/distutils/index.html

本文出自夜惊心的博客,转载请保留出处

【ici】一个python写的字典查询,控制台直接调用/usr/bin/

#encoding:utf-8
from setuptools import setup, find_packages
import sys, os

version = '0.4.1'

setup(name='ici',
      version=version,
      description="方便程序员在terminal查询生词的小工具",
      long_description="""方便程序员在terminal查询生词的小工具""",
      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
      keywords='python iciba dictionary terminal',
      author='yuzhe',
      author_email='lazynightz@gmail.com',
      url='https://github.com/Flowerowl/ici',
      license='',
      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
      include_package_data=True,
      zip_safe=False,
      install_requires=[
        'termcolor',
      ],
      entry_points={
        'console_scripts':[
            'ici = ici.ici:main'    
        ]
      },
)

  

原文地址:https://www.cnblogs.com/yuliyang/p/4361788.html