要將Ubuntu下的Python項目打包發布,可以按照以下步驟進行:
首先,創建一個清晰的項目目錄結構。例如:
/my_project/
|-- qwq_package/
| |-- __init__.py
| |-- mymodule.py
|-- README.md
|-- LICENSE
|-- setup.cfg
|-- setup.py
示例 setup.py
:
from setuptools import setup, find_packages
setup(
name='qwq_package',
version='0.1',
packages=find_packages(),
install_requires=['numpy>=1.18.0', 'pandas>=1.0.0'],
entry_points={
'console_scripts': [
'mymodule=qwq_package.mymodule:main_function',
],
},
)
安裝必要的打包工具:
pip3 install setuptools wheel
在項目根目錄下運行以下命令生成源碼包和二進制包(Wheel包):
python3 setup.py sdist bdist_wheel
這將在 dist/
目錄下生成 qwq_package-0.1.tar.gz
和 qwq_package-0.1-py3-none-any.whl
文件。
twine
上傳生成的包:pip3 install twine
twine upload dist/*
或者使用API token進行上傳:
twine upload --username __token__ --password your-api-token dist/*
用戶可以通過以下命令從PyPI安裝你的包:
pip install qwq_package
requirements.txt
文件記錄所有依賴包及其版本。以上步驟涵蓋了從項目結構到打包發布的完整流程,確保你的Ubuntu Python項目可以順利地打包并發布到PyPI。