zoukankan      html  css  js  c++  java
  • 上传自己的Python代码到PyPI

    一、需要准备的事情

      1、当然是自己的Python代码包了;

      2、注册PyPI的一个账号。

    二、详细介绍

       1、代码包的结构:

        

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

      2、说明

         setup.py是不可缺少的,定义了代码包的详细信息,我们也是通过该模块进行打包,上传等操作。

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

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

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

     3、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' )

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

    4、代码编写完后的工作:

      1)用Python setup.py check检查一下。如果出现running check则表示正常;
    2)敲Python setup.py sdist(保证用pip安装);
    pyhton setup.py bdist_egg (保证easy_install安装)
       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

  • 相关阅读:
    Web下的HTTPS应用
    laravel用crud之index列出产品items
    laravel用crud修改产品items-新建resource controller和routing
    用laravel dingo/api创建产品api
    用laravel dingo/api创建简单的api
    composer错误提示Cloning failed using an ssh key for authentication的解决方法
    防止SQL注入的6个要点
    magento 2.3安装测试数据
    教你一步步composer安装Magento2.3
    30个redis.conf 配置项说明
  • 原文地址:https://www.cnblogs.com/hai-persist/p/4969135.html
Copyright © 2011-2022 走看看