【Python】用setuptools打包项目

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

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

编写setup.py文件

#-*- 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 = "me@example.com",
    # 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安装文件
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值