python工程代码如何打包

2018-08-16  本文已影响0人  Mlotjve
  1. 创建一个空文件夹 example_pkg, 再添加一个同名的子文件夹,包含一个init.py文件. 如下图所示:

     /example_pkg
      /example_pkg
      \__init\__.py
    
  2. 在 _init_.py 文件里面添加如下数据:

name = "example_pkg"

  1. 添加 package 的其他文件
    现在,您将创建一些文件来打包这个项目,并为分发做好准备。创建下面列出的新文件——您将在以下步骤中添加内容。

    /example_pkg
    /example_pkg
      __init__.py
    setup.py
    LICENSE
    README.md
    
  2. 创建 setup.py 文件

    import setuptools
    
    with open("README.md", "r") as fh:
    long_description = fh.read()
    
    setuptools.setup(
        name="example_pkg",
        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",
        ],
    )
    
  1. 创建README.md

     # Example Package
     This is a simple example package. You can use
     [Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/) 
     to write your content.
    
  2. Creating a LICENSE

对于上传到Python包索引的每个包裹来说,包含一个许可证是很重要的。这告诉用户安装包的条款,他们可以使用你的包。为了帮助选择许可证,请参阅https://choosealicense.com/。一旦您选择了许可,打开许可并输入许可文本。例如,如果你选择了MIT的许可

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.

  1. 生成分布档案

python -m pip install --user --upgrade setuptools wheel

image.png

python3 setup.py sdist bdist_wheel

image.png
上一篇 下一篇

猜你喜欢

热点阅读