2.5 setuptools

openstack中的setup.py和setup.cfg的理解 import setuptools # In python < 2.7.4, a lazy loading of package `pbr` will break # setuptools if some other modules registered functions in `atexit`. # solution from: http://bugs.python.org/issue158 阅读详情

 官方文档地址:https://setuptools.pypa.io/en/latest/userguide/quickstart.html

  

pip install --upgrade setuptools wheel
pip install --upgrade build

项目结构

demo -- setup.py

          -- project1 -- utils/

                   -- main.py

                   -- readme.md 

                   -- requirements.txt

1、setup.py方式打包

from setuptools import setup, find_packages, find_namespace_packages
#如果每个包中都有__init__.py则可以使用find_packages
setup(
    name="project1",  #name最好和项目名保持一致,即project1
    version="0.1",
    author='wu',
    description='test',
    packages=find_namespace_packages(exclude=['venv*'],where='project1'),
    package_data={
        '': ['log/*.txt']
    },
    entry_points={
            'console_scripts': [
                'cli-name = src.utils.format:test',
            ]
        }

)

  打包

python -m build  #打包成wheel和tar.gz格式

pip install /dist/demo-0.1-py3-none-any.whl 

 安装后,即可使用cli-name命令行,以及在项目中引入包

from project1.utils.format import test

 其他打包方式

python setup.py sdist --formats=zip

python setup.py bdist

安装

python setup.py install

argument name

value

type

name

The name of the package

a string

version

The version number of the package; see distutils.version

a string

description

A single line describing the package

a string

long_description

Longer description of the package

a string

author

The name of the package author

a string

author_email

The email address of the package author

a string

maintainer

The name of the current maintainer, if different from the author. Note that if the maintainer is provided, distutils will use it as the author in PKG-INFO

a string

maintainer_email

The email address of the current maintainer, if different from the author

a string

url

A URL for the package (homepage)

a string

download_url

A URL to download the package

a string

packages

A list of Python packages that distutils will manipulate

a list of strings

py_modules

A list of Python modules that distutils will manipulate

a list of strings

scripts

A list of standalone script files to be built and installed

a list of strings

ext_modules

A list of Python extensions to be built

a list of instances of distutils.core.Extension

classifiers

A list of categories for the package

a list of strings; valid classifiers are listed on PyPI.

distclass

the Distribution class to use

a subclass of distutils.core.Distribution

script_name

The name of the setup.py script - defaults to sys.argv[0]

a string

script_args

Arguments to supply to the setup script

a list of strings

options

default options for the setup script

a dictionary

license

The license for the package

a string

keywords

Descriptive meta-data, see PEP 314

a list of strings or a comma-separated string

platforms

a list of strings or a comma-separated string

cmdclass

A mapping of command names to Command subclasses

a dictionary

data_files

A list of data files to install

a list

package_dir

A mapping of package to directory names

a dictionary

 2、pyproject.toml方式

文档地址:https://packaging.python.org/en/latest/specifications/declaring-project-metadata/

上述目录根目录中新建pyproject.toml,setup.py中注释掉setup()方法中的参数,仅保留如下内容

from setuptools import setup

setup()
#pyproject.toml
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "project1"
authors = [
    {name = "wu", email = "wu@brown.edu"},
]
description = "My package description"
readme = "README.rst"
requires-python = ">=3.7"
keywords = ["one", "two"]
license = {text = "BSD-3-Clause"}
classifiers = [
    "Framework :: Django",
    "Programming Language :: Python :: 3",
]
dynamic = ["version"]
[project.scripts]
cli-name = "project1.utils.format:test"
#其他可用的table如下
#[project.optional-dependencies]
#[project.urls]
#[project.gui-scripts]
#[project.entry-points."spam.magical"]

 

python -m build   #打包

3、 setup.cfg打包

文档地址:https://setuptools.pypa.io/en/latest/userguide/declarative_config.html

新建setup.cfg文件

[metadata]
name = porject1
author = wu
author_email = wu@brown.edu
description = My package description
long_description = test
keywords = one, two
license = BSD-3-Clause
classifiers =
    Framework :: Django
    Programming Language :: Python :: 3

[options]
zip_safe = True
include_package_data = True
packages = find:
python_requires = >=3.7

[options.package_data]
* = *.txt, *.rst

[options.entry_points]
console_scripts =
    cli-name = project1.utils.format:test

[options.extras_require]
pdf = ReportLab>=1.2; RXP
rest = docutils>=0.3; pack ==1.1, ==1.3

[options.packages.find]
exclude =
    venv*
where=project1

 执行

python -m build

三种方式均能起到打包的作用 

Python 包发布实战:Twine 6.2.0 与 setuptools 68.0.0 配置 5 个关键步骤 本文详细介绍了使用最新版 Twine 6.2.0 和 setuptools 68.0.0 发布 Python 包到 PyPI 的五个关键步骤,包括项目结构配置、安全认证、构建验证、上传流程和 CI/CD 集成。内容涵盖现代 Python 打包最佳实践,帮助开发者高效安全地分发代码。 阅读详情

相关推荐

跟着李沐学AI却卡在环境搭建?手把手教你修复Anaconda安装setuptools报错(Python 3.8.5 + d2l-zh环境)

本文详细解析了在Anaconda环境下安装setuptools时遇到的常见报错问题,特别是在Python 3.8.5和d2l-zh环境中。通过深度排查镜像源、版本兼容性和依赖冲突,提供了精确版本锁定和环境清理的解决方案,帮助开发者快速搭建稳定的深度学习环境。

weixin_30335575的博客 303

openstack中setup.cfg文件解析

一 介绍setup.cfg文件,作为openstack中的源码地图,毫不夸张的说,是我们浏览openstack代码时最为依仗的文件,它引导我们去认识一个新的项目,并了解它代码的结构。而入口点"entry_point”作为setup.cfg中最重要的section,通过对它的分析,我们可以相对容易地找到所要研究代码的突破口。每个setup.cfg文件的"entry_point”都会有个比较特殊的组,...

实践求真知 2157

深度探索:非线性随机森林(Nonlinear Random Forest,NL-RF)原理及应用

非线性随机森林(NL-RF)旨在通过结合集成方法与高级技术来捕捉和建模数据中的非线性关系,从而改善传统随机森林在处理复杂非线性数据结构时的表现。

qq_51320133的博客 2064

python安装setuptools(easy_install工具)

想装个readability,结果自己的windows上没有装easy_install,所以bud

holybin的专栏 6664

CNN经典论文(一)LeNet

Gradient-Based Learning Applied to Document Recognition(梯度学习在文档识别中的应用) Yann LeCun, Leon Bottou, Yoshua Bengio, and Patrick Haffner 发表时间:December 1998 期刊:Proceedings of the IEEE 影响:世界上第一个卷积神经网络 论文地址:Gradient-Based Learning Applied to Document Recognition

loveling丶的博客 3597

电动转向系统 TAS 传感器

靠扭杆变形测力气,用霍尔效应算角度,借 ECU 给电机发指令。它就像 EPS 系统的 "神经末梢",把驾驶员的操作意图转化成电信号,再通过电机变成实实在在的助力,让我们开车既省力又安全。下次转动方向盘时,不妨想想这个藏在转向柱里的 "小传感器"—— 正是它的精准感知,才有了每一次顺畅的转向体验。

weixin_59825476的博客 4276

python打包两种方式:setup.py、pyproject.toml;entry_points、project.scripts 可执行的命令行

参考: https://blog.csdn.net/qq_38844437/article/details/126628564 https://click.palletsprojects.com/en/7.x/setuptools/#setuptools-integration学习写法:https://github.com/myshell-ai/MeloTTS/blob/main/setup.pyyourscript.py: setup.py: pyproject.toml 参考:https://blog.

weixin_42357472的博客 3031

ComfyUI面部修复FaceDetailer保姆级教程:从模型选择到参数调优全解析

本文提供ComfyUI面部修复FaceDetailer的保姆级教程,深度解析从模型选择到参数调优的全过程。针对常见的五官模糊、肤色不均等问题,详细对比了BBox与Segm检测器的优劣,并给出SD1.5与SDXL模型的核心参数联动策略与实战方案,帮助用户精准掌控AI绘画中的面部修复效果。

weixin_29073241的博客 471

python 升级setuptools_Centos 5.x 升级 python2.7,安装setuptools、mysqldb 完整记录

最近由于有个工作任务需要搭个虚拟机环境,但是环境是搭建在内网,无法直接联网,很多软件都不能直接yum安装,安装过程实在十分不顺利,在此留个记录给有需要的朋友。环境是 CentOS 5.7 x64请选择合适的方式,下载python2.7.3安装包安装前当然需要编译器gccyuminstallgcc为了安装setuptools,要需要安装zlibyuminstallzlibzlib-dev解...

weixin_36110344的博客 285

深入SVT SPI VIP配置:如何灵活控制CS间隔、数据帧大小与时钟频率(含代码片段)

本文深入探讨了SVT SPI VIP的高级配置技巧,包括精确控制CS信号间隔、突破数据帧大小限制以及动态时钟频率切换。通过实战代码片段和详细配置步骤,帮助验证工程师灵活应对复杂SPI协议验证场景,提升验证效率和覆盖率。特别适合需要处理非标准SPI时序和特殊数据帧的芯片验证项目。

weixin_27014595的博客 280

2024年数字IC秋招-华为机试-数字芯片-实习笔试题

笔试题目:40个选择题A.综合时不同文件列表内的宏定义仅在本列表生效B.宏定义会覆盖,不需要单独undefC.仿真时出现宏定义冲突以最后一次值为准D.宏定义最好在各文件中随用随定义A.4/9B.4/6C.01D.0/6。

qq_42135020的博客 2891

在ubuntu上用安装python-2.7.5和setuptools-0.9.8

1下载并解压python mkdir Python         cd Python         wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz (这是python-2.7.5压缩包下载地址)         tar -zxvf Python-2.7.5.tgz  2改动/Python/Python-2.

tdmyl的专栏 6565

计算机组成原理(第三版)唐朔飞-第五章输入输出系统-课后习题

计算机组成原理(第三版)唐朔飞-第五章输入输出系统-课后习题

weixin_45735391的博客 6万+

python 2.7.5 安装 pip、 setuptools 以及第三方控件PIL

安装python2.7.5并配置环境 1 先安装setuptools    下载地址:https://pypi.python.org/pypi/setuptools#downloads  将下载后的tar文件解压,用CMD模式进入到解压后的文件所在的目录执行命令:python setup.py install 2 安装pip   下载地址:https://

宜臶瑏芯的博客 2455

【25届数字IC秋招总结】面试经验10——紫光同芯

25届数字ic面试记录——紫光同芯

lalala0635的博客 862

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

linux环境Mechanize安装,在linux下安装activepython2.5 setuptools ClientCookie

activepythonhttp://www.activestate.com/products/activepython/是ActiveState Software的一个python的分发包,带了一些python的扩展.setuptoolshttp://cheeseshop.python.org/pypi/setuptools是一个python的包,它可以简化python包的下载,build,安装...

weixin_29310631的博客 210

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

python离线安装pip_Python2.7.5离线安装setuptools、pip和requests包

文章目录概述在内网CentOS7操作系统Python2.7.5环境下是不能联网安装各个服务。setuptools安装下载:https://files.pythonhosted.org/packages/24/49/7f567b628e14ee004938eec256cffeae7097db9e28576911ae7b84d2ff07/setuptools-41.1.0.post1.tar.gz使用...

weixin_39562752的博客 1216

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

CentOS 5 上安装 Python setuptools 2.6

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34216036的博客 106

Centos 5.x 升级 python2.7,安装setuptools、mysqldb 完整记录

http://blog.csdn.net/jeffreynicole/article/details/8280358 最近由于有个工作任务需要搭个虚拟机环境,但是环境是搭建在内网,无法直接联网,很多软件都不能直接yum安装, 安装过程实在十分不顺利,在此留个记录给有需要的朋友。 环境是 CentOS 5.7 x64 请选择合适的方式,下载python2.7.

662

Python2.7.5离线安装setuptools、pip和requests包

文章目录概述setuptools安装pip离线安装requests安装 概述 在内网CentOS7操作系统Python2.7.5环境下是不能联网安装各个服务。 setuptools安装 下载: https://files.pythonhosted.org/packages/24/49/7f567b628e14ee004938eec256cffeae7097db9e28576911ae7b84d2f...

TT-Learning 7761

python 升级setuptool_Centos6.5 python2.6.6升级2.7.13,安装setuptools和pip

1、安装Development Tools和相关编译安装的组件#yum-ygroupinstall"Developmenttools"#yum-yinstallopenssl-develzlib-develncurses-develbzip2-develreadline-devellibtool-ltdl-develsqlite-develtk-develtcl-d...

weixin_39596975的博客 174

setuptools python2.7_centos 6.5安装python2.7.10和setuptools和pip

如果你使用yum安装,那么源里的python 基本不会超过2.7目前官方最新的版本是2.7.10 (也许你看到该文章时已经不止了)所以我们要手工编译安装。 编译安装python比其他 方便多了。很可爱。1、确认你的centos有编译的环境以及工具如gcc.如果完全不知道这些,那么你可以安装全部工具执行这个 yum groupinstall “Development tools”然后再执行这个:...

weixin_32367041的博客 241

python之——CentOS 6.5安装Python setuptools2.6

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/79069295 在 PyPI 可以找到 setuptools 的安装文档: http://pypi.python.org/pypi/setuptools 下载 setuptools-0.6c11-py2.6.egg 也可以到链接:http://download.cs

冰河的专栏 2801
上一篇: 2.4 pytest自动化实现问题记录
下一篇: 2.6 装饰器
LetsStudy
博客等级 码龄9年 96粉丝 323原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值