如何发布一个pip包
准备
注册号账号: https://pypi.org/account/register/
编码
code
pip install build
pip install twine
pip install setuptools wheel
touch setup.py
setup.py
from setuptools import setup
from os import path
print(path.abspath(path.dirname(__file__)))
with open(
path.join(path.abspath(path.dirname(__file__)), 'README.md'),
encoding='utf-8') as f:
long_description = f.read()
setup(
name='utilset',
version='0.0.1',
author='puresai',
url='https://github.com/puresai/utilset',
description="util sets",
long_description_content_type="text/markdown",
long_description=long_description,
packages=['utilset'],
install_requires=[],
platforms=["all"],
classifiers=[
'Intended Audience :: Developers', 'Operating System :: OS Independent',
'Natural Language :: Chinese (Simplified)',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Software Development :: Libraries'
],
)
deploy
python3 setup.py check
rm -rf dist
python3 -m build
python3 -m twine upload dist/*
apitoken
upload 之前是可以输入用户名密码的,但是几年有所变化,可以使用 apitoken 上传。
可以点击前往 https://pypi.org/manage/account/ 新建一个 apitoken,然后新建个 ~/.pypirc
[distutils]
index-servers=pypi
[pypi]
repository: https://upload.pypi.org/legacy/
username = __token__
password = pypi-xxxx-xxx
source ~/.pypirc
然后上传就行,成功上传后就可以在pypi账户下看到自己的项目 https://pypi.org/manage/projects/了,可以 install 后使用了。
如何发布一个pip包
https://blog.puresai.com/2024/03/21/510/