上传本身的Python代码到PyPI

 

1、须要准备的事情html

  一、固然是本身的Python代码包了;python

  二、注册PyPI的一个帐号。bash

 

2、详细介绍app

   一、代码包的结构:函数

    

application

  \application
       __init__.py
      myapplication.py
      ......
   \docs
  README.txt setup.py

  二、说明ui

     setup.py是不可缺乏的,定义了代码包的详细信息,咱们也是经过该模块进行打包,上传等操做。url

     docs是项目文档,能够经过sphinx生成。可在setup模块中经过参数实现,long_description=__doc__,详见下面代码。spa

     README.txt是对整个代码包的描述。code

     application是本项目的代码包,代码包嘛,必需要有__init__.py文件。orm

 三、setup.py编写

     

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup
"""
这里这么写的目的是防止setup导入出错,安装出现异常。但通常不会出错
"""
setup( name
='haibo', version='0.1.2',#该信息是必不可少的 author='haibo', author_email='hbnnlong@163.com', description='haibo universal function', license='MIT', packages=['haibo',],#须要安装的代码包,也能够用find_packages函数 install_requires=['mako>=1.0.3', ],#一些第三方帐号,须要在这里申明。 classifiers = [ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Intended Audience :: Developers', 'Operating System :: OS Independent', ],#这也须要遵循标准格式 keywords='haibo function', url='hbnnlove.sinaapp.com', zip_safe=True,#设为True,以zip的方式进行传输 include_package_data=True,#字面意思就可理解 platforms='any' )

..............

 

四、代码编写完后的工做:

 1)用Python setup.py check检查一下。若是出现running check则表示正常;
2)敲Python setup.py sdist(保证用pip安装);
pyhton setup.py (保证easy_install安装)
bdist_egg
3)执行python setup.py register sdist bdist_egg upload进行上传。
在该步骤中须要输入你在PyPI的用户名和密码。

 

参考文献:

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

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

相关文章
相关标签/搜索