【Python】用setuptools打包项目

创建项目文件夹和setup.py文件

  • 项目目录结构:
work->  
    project_file->
        __init__.py
        hello.py
    setup.py

编写setup.py文件

  • 要先安装setuptools:下载安装setuptools
#-*- encoding: UTF-8 -*-
from setuptools import setup

setup(
    name = "HelloWorld",          # 包名
    version = "0.1",              # 版本信息
    packages = ['project_file'],  # 要打包的项目文件夹
    include_package_data=True,    # 自动打包文件夹内所有数据
    zip_safe=True,                # 设定项目包为安全,不用每次都检测其安全性

    install_requires = [          # 安装依赖的其他包
    'docutils>=0.3',
    'requests',
    ],

    # 设置程序的入口为hello
    # 安装后,命令行执行hello相当于调用hello.py中的main方法
    entry_points={
        'console_scripts':[
            'hello = project_file.hello:main'
        ]
     },

    # 如果要上传到PyPI,则添加以下信息
    # author = "Me",
    # author_email = "[email protected]",
    # description = "This is an Example Package",
    # license = "MIT",
    # keywords = "hello world example examples",
    # url = "http://example.com/HelloWorld/",   
 )

安装并执行

  • 安装:python setup.py install
    另外:
  • 执行:python setup.py sdist会在dist文件夹生成项目的压缩包
  • 执行:python setup.py bdist_wininst会生成exe安装文件

你可能感兴趣的:(【Python】用setuptools打包项目)