时间:2021-05-22
如果需要将自己写好的python打包,并发布到pypi,这样其他人就可以直接通过pip install来安装对应的包,可以参考如下教程
首先访问https://pypi.org/ 并注册账号
然后跳转到账号设置
然后选择API token->Add API token
输入token name并在Scope中选择Entire account(第一次需要选择Entire account)
然后在本地,修改.pypirc文件
输入的内容为:
只需要修改{token}为自己的token即可
setup.cfg的内容为
[metadata]license_files = LICENSE.txtLICENSE.txt是license文件,需要自行编写
setup.py在根目录下,一个示例为
具体的字段含义如下:
name: 包名
version: 版本号,支持如下形式
1.2.0.dev1 # Development release1.2.0a1 # Alpha Release1.2.0b1 # Beta Release1.2.0rc1 # Release Candidate1.2.0 # Final Release1.2.0.post1 # Post Release15.10 # Date based release23 # Serial releasedescription: 包描述,会放在如下图所示的位置处
url: 包的链接,可以使用github链接,pypi会自动获取到仓库的信息,示例如下:
author: 作者
license: 许可证
classifiers: 分类,示例如下:
classifiers=[ # How mature is this project? Common values are # 3 - Alpha # 4 - Beta # 5 - Production/Stable 'Development Status :: 3 - Alpha', # Indicate who your project is intended for 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', # Pick your license as you wish (should match "license" above) 'License :: OSI Approved :: MIT License', # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9',],keywords: 关键字,和论文的关键字类似
project_urls: 一些项目的其他链接,示例如下
project_urls={ 'Documentation': 'https://packaging.python.org/tutorials/distributing-packages/', 'Funding': 'https://donate.pypi.org', 'Say Thanks!': 'http://saythanks.io/to/example', 'Source': 'https://github.com/pypa/sampleproject/', 'Tracker': 'https://github.com/pypa/sampleproject/issues',},packages: 需要打包的目录,需要以根目录为起点,可以使用
find_packages自动查找包,注意不要漏写
install_requires: 包依赖的其他包
python_requires: python的版本需求
package_data: 需要的额外的文件,例如包强依赖一个本地文件,可以使用如下
package_data={ 'sample': ['package_data.dat'],},打包命令为
python setup.py cmdcmd可以取值为
bdist_wheel : create a wheel distribution
bdist_egg : create an “egg” distribution
sdist : create a source distribution (tarball, zip file, etc.)
bdist : create a built (binary) distribution
bdist_dumb : create a “dumb” built distribution
bdist_rpm : create an RPM distribution
bdist_wininst : create an executable installer for MS Windows
打包为tar.gz
python setup.py sdist打包好的文件再dist目录下
可以首先使用twine对包进行检查
twine check dist/*输出如下
再运行上传命令
twine upload dist/*到此这篇关于用Python将库打包发布到pypi的文章就介绍到这了,更多相关python打包到pypi内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
使用场景已搭建了PyPI私有库,上传公共库包含静态文件,如需要使用sql静态文件初始化数据库。打包python包,给其他人使用,但项目中包含静态文件,如html
python的字符串编码识别模块(第三方库):官方地址:http://pypi.python.org/pypi/chardetimportchardetimpo
1.在python中excel的简单读写操作,推荐使用xlrd(特别是读操作)2.到http://pypi.python.org/pypi/xlrd去下载xlr
Python项目打包python本身是一种脚本语音,发布的话,直接发布源代码就可以了,但是,可能有些公司并不想发布源代码,那么,就涉及到打包了,网上有很的打包教
安装先下载源码,地址:ps://pypi.python.org/pypi/IPy/">https://pypi.python.org/pypi/IPy/,然后解