python distutils 基本打包与发布
2024-09-08 07:02:02
distutils 实现对package 包的发布
import math def showMsg(a):
return a * a * a a = 10
print('%d 的三次方是 %d' % (a, showMsg(a)))
package.py
1. 在同级目录下建立setup.py
# encoding=utf-8
from distutils.core import setup,Extension # 打包软件脚本文件必须采用 setup 名称
# 打包函数
setup(
name='package', # 安装包名
version='1.0', # 打包安装软件的版本号
description="实现对数的三次方运算",
long_description="实现对数的三次方运算",
author= 'feiquan123',
author_email= '2283320260@qq.com',
# maintainer="None", # 提供与包相关的其他维护者的名字
# maintainer_email="None", # 其他维护者的邮箱
url="", # 包相关网站主页的的访问地址
download_url="", # 下载安装包(zip , exe)的url
keywords="math",
py_modules=['package'], # 设置打包模块,可以多个
# 对于C,C++,Java 等第三方扩展模块一起打包时,需要指定扩展名、扩展源码、以及任何编译/链接 要求(包括目录、链接库等)
ext_modules = [Extension('data',['data.c'])],
)
注意:如果你的setup.py 中包含中文字符,第一行的代码必须写
如何扩展和嵌入 Python 解释器 : https://docs.python.org/zh-cn/3/extending/index.html
2. 编写安装配置文件 setup.cfg
[sdist]
dist-dir = source
dist-dir : 指定发布源码的路径,默认 dist
如何编写setup.cfg:
Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/'
setup.py install will install the package Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message
--no-user-cfg ignore pydistutils.cfg in your home directory Options for 'sdist' command:
--template (-t) name of manifest template file [default: MANIFEST.in]
--manifest (-m) name of manifest file [default: MANIFEST]
--use-defaults include the default file set in the manifest
[default; disable with --no-defaults]
--no-defaults don't include the default file set
--prune specifically exclude files/directories that should
not be distributed (build tree, RCS/CVS dirs, etc.)
[default; disable with --no-prune]
--no-prune don't automatically exclude anything
--manifest-only (-o) just regenerate the manifest and then stop (implies
--force-manifest)
--force-manifest (-f) forcibly regenerate the manifest and carry on as
usual. Deprecated: now the manifest is always
regenerated.
--formats formats for source distribution (comma-separated
list)
--keep-temp (-k) keep the distribution tree around after creating
archive file(s)
--dist-dir (-d) directory to put the source distribution archive(s)
in [default: dist]
--medata-check Ensure that all required elements of meta-data are
supplied. Warn if any missing. [default]
--owner (-u) Owner name used when creating a tar file [default:
current user]
--group (-g) Group name used when creating a tar file [default:
current group]
--help-formats list available distribution formats usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
setup.py --help sdist
3. 发布软件 (压缩包)
linux : python setup.py sdist
windows : setup.py sdist
指定发布格式,同时生成两个压缩包: python setup.py sdist --formats=gztar,zip
windows exe : python setup.py bdist_wininst
--formats:
zip -> .zip
gztar -> .tar.gz
bztar -> .tar.bz2
ztar -> .tar.Z
tar -> .tar
4. 安装源码包,然后你就可以导入了
解压后cd 到解压目录
安装命令 python setup.py install
或者安装时保存安装日志: python setup.py install --record log
5. 安装后删除
1. 安装时记录日志 python setup.py install --record log
2. windows : for /F %i in (log) do del %i
linux : cat log | xagrs rm -rf
其中: log文件内容是安装目录:
E:\...\Lib\site-packages\package.py
E:\...\Lib\site-packages\__pycache__\package.cpython-37.pyc
E:\...\Lib\site-packages\package-1.0-py3.7.egg-info
最新文章
- 版本控制工具比较-CVS,SVN,GIT
- display:inline-block会产生空隙
- HTML5和css3的总结二
- 关于MSSQL导入导出时主键与约束丢失的问题解决
- window live writer的曲折安装过程
- Codeforces Round #322 (Div. 2) D. Three Logos 暴力
- 用PHP添加购物商品
- phalcon的一些中文手册和帮助文档地址收集
- Windows Media Player Plus
- 处理SFTP服务器上已离职用户,设置为登录禁用状态
- Ubuntu 16下安装64位谷歌Chrome浏览器
- Hierarchical clustering:利用层次聚类算法来把100张图片自动分成红绿蓝三种色调—Jaosn niu
- 使用nvm安装node,全局npm,cnpm
- Python全栈之路----函数----参数
- P1099 树网的核
- Prometheus Node_exporter
- 第十章 优先级队列 (xa2)左式堆:合并
- C10K并发连接_转
- 【MySQL笔记】解除输入的安全模式,Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
- python的对象类型-----列表&;元组&;字典
热门文章
- 运算符副作用总结与例子(js)
- html5+css3的神奇搭配
- 深度强化学习(DQN-Deep Q Network)之应用-Flappy Bird
- [ASP.NET Core 3框架揭秘] 配置[7]:多样化的配置源[中篇]
- 【第二版】高仿Android网易云音乐企业级项目实战课程介绍
- IDEA开发、测试、生产环境pom配置及使用
- Caffeine批量加载浅析
- laravel身份验证-Auth的使用
- 基于V6的中移动物联测试例子,当前测试还挺稳定
- docker chromium/chrome: error while loading shared libraries: libXcursor.so.2: cannot open shared object file: No such file or directory