目录
setup.py
文件,其中包含有关您的包的信息(名称、版本、依赖等)。README.md
或 README.rst
文件,说明您的项目。LICENSE
文件,说明您的包的许可证。my_package/
setup.py
README.md
LICENSE
my_package/
__init__.py
module1.py
module2.py
from setuptools import setup, find_packages
setup(
name='my_package',
version='0.1',
packages=find_packages(),
description='A simple example package',
long_description=open('README.md').read(),
# python3,readme文件中文报错
# long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
url='http://github.com/yourusername/my_package',
author='Your Name',
author_email='your.email@example.com',
license='MIT',
install_requires=[
# 依赖列表
],
classifiers=[
# 分类信息
]
)
在软件和开源项目中,LICENSE
文件非常重要,它定义了他人可以如何使用、修改、共享你的代码。LICENSE
文件通常包含了特定的许可证全文,这个许可证规定了对代码的使用权限和限制。
MIT License:一种非常宽松的许可证,允许他人几乎无限制地使用你的代码。
GNU General Public License (GPL):要求任何分发的软件或其衍生品都必须开源。
Apache License 2.0:允许商业使用,但要求保留版权和许可证声明。
BSD License:一种简单的许可证,有几个不同的变体,但通常都很宽松。
一个典型的 MIT 许可证:
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
在这个例子中,你需要将 [year]
替换为当前年份,[fullname]
替换为你的名字或组织名。?
地址:https://pypi.org/,注册账号,注册后,需要双因素认证,可使用恢复代码、usb、扫码(支持 TOTP 标准的常用扫码工具,Google Authenticator、Authy、Microsoft Authenticator、LastPass Authenticator)
setup.py层级,执行命令:
python setup.py sdist bdist_wheel
# 若报错时报了错,先安装wheel
pip install wheel
twine
是一个用于上传包到 PyPI 的工具。您可以通过 pip 安装它:
pip install twine
twine upload dist/*
上传问题,具体问题具体网上搜素:
(1)名称不能重复
(2)输入用户名密码,在pypi账号设置,Account settings中,创建token,账号密码不能上传了,创建后记录号token,然后上传,用户名默认:__token__ 密码:生成的key
pip install my_package