Python package their own package

Own packaged as whl / tar.gz file

Sometimes a developer to write a basic class, we put this class packaged as whl or tar.gz files, so you can use your own colleagues developed the basic classes

Install setuptools

pip install setuptools

Write setup.py and __init__.py file ( the init .py content can be empty)

Note the directory structure

packages/
  __init__.py
  自己的文件.py
setup.py
Readme.txt

setup.py file contents

from setuptools import setup
setup(name='dingding-py',
      version='0.0.2',
      description='this is a dingdingbot packages',
      author='Jruing',
      author_email='[email protected]',
      packages=['Qingolddriver']

      )

In addition to the above examples there are several parameters other

name : 打包后包的文件名
version : 版本号
author : 作者
author_email : 作者的邮箱
py_modules : 要打包的.py文件
packages: 打包的python文件夹
include_package_data : 项目里会有一些非py文件,比如html和js等,这时候就要靠include_package_data 和 package_data 来指定了。package_data:一般写成{‘your_package_name’: [“files”]}, include_package_data还没完,还需要修改MANIFEST.in文件.MANIFEST.in文件的语法为: include xxx/xxx/xxx/.ini/(所有以.ini结尾的文件,也可以直接指定文件名)
license : 支持的开源协议
description : 对项目简短的一个形容
ext_modules : 是一个包含Extension实例的列表,Extension的定义也有一些参数。
ext_package : 定义extension的相对路径
requires : 定义依赖哪些模块
provides : 定义可以为哪些模块提供依赖
data_files :指定其他的一些文件(如配置文件),规定了哪些文件被安装到哪些目录中。如果目录名是相对路径,则是相对于sys.prefix或sys.exec_prefix的路径。如果没有提供模板,会被添加到MANIFEST文件中。

Bale

Into the directory where setup.py execute the following command

python setup.py bdist_wheel # packaged as whl file
packaged as tar.gz file python setup.py sdist #
file after the package can be found packaged in the dist directory

Guess you like

Origin www.cnblogs.com/jruing/p/12650538.html