上傳本身的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

相關文章
相關標籤/搜索