自定义Package开发

CitoryTech2022年11月18日大约 1 分钟

安装whell

pip install whell

新建项目目录:

setup.pyopen in new window

from setuptools import setup, find_packages

setup(
    name='ct_geoc',
    version='1.0',
    packages=find_packages(),
)

init.py

from .geoc import some_function 

geoc.pyopen in new window(自定义文件名)

def some_function():
    do_something()

开始打包

python setup.py bdist_wheel

完成打包,生成了文件

引入包

from ct_geoc import some_function

常用参数以及打包技巧

setup函数各参数详解:
>>python setup.py --help
  --name              包名称
  --version (-V)      包版本
  --author            程序的作者
  --author_email      程序的作者的邮箱地址
  --maintainer        维护者
  --maintainer_email  维护者的邮箱地址
  --url               程序的官网地址
  --license           程序的授权信息
  --description       程序的简单描述
  --long_description  程序的详细描述
  --platforms         程序适用的软件平台列表
  --classifiers       程序的所属分类列表
  --keywords          程序的关键字列表
  --packages  需要打包的目录列表
  --py_modules  需要打包的python文件列表
  --download_url  程序的下载地址
  --cmdclass  
  --data_files  打包时需要打包的数据文件,如图片,配置文件等 data_files=[("",[pro/t.txt])]
  --scripts  安装时需要执行的脚步列表 scripts = ['bin/fcon']

setup.py打包命令各参数详解:
>>python setup.py --help-commands
  --python setup.py build     # 仅编译不安装
  --python setup.py install    #安装到python安装目录的lib下
  --python setup.py sdist      #生成压缩包(zip/tar.gz)
  --python setup.py bdist_wininst  #生成NT平台安装包(.exe)
  --python setup.py bdist_rpm #生成rpm包
上次编辑于:
贡献者: shaojinxin
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.14.1