將Python代碼發布到PyPi,使他人可用pip安裝__Python

來源:互聯網
上載者:User


項目的大致目錄結構,其中bword/bword.py 是你的代碼檔案,__init__.py檔案聲明此目錄為一個模組,你可以完全不在裡面寫任何內容,也可以寫一些代碼。如果你還不明白你可以參照:https://github.com/ZhangHang-z/bword 的目錄結構
項目的根目錄要有一個setup.py檔案,這個檔案建立後還可以使用 python setup.py install 安裝你的模組,很熟悉吧。目錄裡的配置詳情:


from setuptools import setup, find_packagessetup(      name='bword',   #名稱      version='0.10',  #版本      description="a console translation dictionary used dict.baidu.com Api", #描述      keywords='python english translation dictionary terminal',      author='zhanghang',  #作者      author_email='stevezhang@gmail.com', #作者郵箱      url='https://github.com/zhanghang-z', #作者連結      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),      include_package_data=True,      zip_safe=False,      install_requires=[      #需求的第三方模組        'requests',      ],      entry_points={        'console_scripts':[     #如果你想要以Linux命令的形式使用            'bword = bword.bword:main'            ]      },)



去PyPi上註冊一個帳號 https://pypi.python.org/pypi?%3Aaction=register_form 在你的使用者家目錄 ~/ 下建立一個名為 .pypirc 的隱藏檔案,將你的帳號密碼填入:

 [server-login]
 username = 
 password = 



$  python setup.py check   # 檢查 setup.py 的文法正不正確

正確會輸出 running check


$ python setup.py sdist

會輸出一些檔案,包括.tar.gz檔案



$ python setup.py register sdist upload  

上傳至PyPi


如果以後修改了代碼需要更新PyPi上則需要修改setup.py裡的版本號碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.