在Ubuntu上打包发布Python项目,可参考以下步骤:
my_package
代码目录、tests
测试目录、README.md
文档、setup.py
配置文件、LICENSE
许可证文件等。setup.py
:用setuptools
定义项目元数据和依赖,例如name
、version
、packages
、install_requires
等参数。pip install setuptools wheel
安装setuptools
和wheel
。python setup.py sdist bdist_wheel
,生成.tar.gz
源分发包和.whl
二进制轮子包,存于dist
目录。twine
工具,使用twine upload dist/*
将包上传到PyPI。也可先上传到TestPyPI测试,命令为twine upload --repository-url https://test.pypi.org/legacy/ dist/*
。此外,还可使用CI/CD工具如GitHub Actions实现自动化打包发布。