withopen("README.md", "r") as fh: long_description = fh.read()
setuptools.setup( name="example-pkg-YOUR-USERNAME-HERE", # Replace with your own username version="0.0.1", author="Example Author", author_email="author@example.com", description="A small example package", long_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", ], python_requires='>=3.6', )
setup() 的几个最必须的参数如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
nameis the distribution nameof your package. This can be anynameas long asonly contains letters, numbers, _ , and -. It also must not already be taken on pypi.org. Be sure toupdate this with your username, as this ensures you won’t try to upload a package with the same nameas one which already existswhen you upload the package.
versionis the package version see PEP 440for more details on versions.
author and author_email are used to identify the author of the package.
description is a short, one-sentence summaryof the package.
long_description is a detailed description of the package. This is shown on the package detail package on the Python Package Index. In this case, the long description is loaded from README.md which is a common pattern.
long_description_content_type tells the index what typeof markup is used for the long description. In this case, it’s Markdown.
url is the URL for the homepage of the project. For many projects, this will just be a link to GitHub, GitLab, Bitbucket, orsimilar code hosting service.
packages is a list ofall Python import packages that should be included in the distribution package. Insteadof listing each package manually, we can use find_packages() to automatically discover all packages and subpackages. In this case, the list of packages will be example_pkg as that’s the only package present.
classifiers gives the indexand pip some additional metadata about your package. In this case, the package isonly compatible with Python 3, is licensed under the MIT license, andis OS-independent. You should alwaysinclude at least which version(s) of Python your package works on, which license your package is available under, and which operating systems your package will workon. For a complete list of classifiers, see https://pypi.org/classifiers/.
创建README.md
创建 README.md ,写上你准备写入的内容:
1 2 3 4 5
# Example Package
Thisis a simple example package. You can use [Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/) to write your content.
创建LICENSE
比如使用MIT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Copyright (c) 2018 The Python Packaging Authority
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.