參考 "Packaging Python Projects" , 源碼在 "nobodxbodon/test package for pypi" : setup.py中 與編寫Visual Studio Code插件初嘗試類似, name只能用英文. 生成發佈包 上傳到測試pypi平臺 測試安裝包. ...
參考Packaging Python Projects, 源碼在nobodxbodon/test-package-for-pypi
包名/__init__.py
:
測試變數 = "值"
setup.py中
import setuptools
with open("README.md", "r") as 自述文件:
長描述 = 自述文件.read()
setuptools.setup(
name="test-package-name",
version="0.0.4",
author="小名",
author_email="[email protected]",
description="描述",
long_description=長描述,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
與編寫Visual Studio Code插件初嘗試類似, name只能用英文.
生成發佈包
$ python3 -m pip install --user --upgrade setuptools wheel
$ python3 setup.py sdist bdist_wheel
上傳到測試pypi平臺
$ python3 -m pip install --user --upgrade twine
$ python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
測試安裝包. 今後最好用virtualenv
$ python3 -m pip install --index-url https://test.pypi.org/simple/ test-package-name
現在就可以導入包
>>> import 包名
>>> 包名.測試變數
'值'
接下去需要將之前的擴展Python控制台同樣打包併發布到(非測試)pypi平臺, 但要先搞定開發模式(Packaging and distributing projects), 以及在命令行下調用控制台. 參考:
- 周蟒實現: https://github.com/gasolin/zhpy/blob/master/zhpy2/setup.py#L44
- How to package a command line Python script