首页 > 编程语言 >python打包工具distutils

python打包工具distutils

时间:2022-11-22 23:02:45浏览次数:42  
标签:1.0 distutils python setup py module hello 打包

参考: http://www.cppcns.com/jiaoben/python/225742.html

python源码包安装:python setup.py install

distutils

distutils 是 python 标准库的一部分,这个库的目的是为开发者提供一种方便的打包方式, 同时为使用者提供方便的安装方式。当我们开发了自己的模块之后,使用distutils的setup.py打包。

hello.py
import time
print("Current time:",time.asctime())
def hello_fun():
    print("This is my function hello")
setup.py
from distutils.core import setup
setup(
     name="hello_module",
     version="1.0",
     author="",
     author_email="",
     py_modules=['hello'],
)

执行打包命令 python setup.py sdist

C:\Users\23798\Desktop\desktop\my_note\python_project\mysetuptool>python setup.py sdist
running sdist
running check
warning: check: missing required meta-data: url
warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
writing manifest file 'MANIFEST'
creating hello_module-1.0
copying files to hello_module-1.0...
copying README -> hello_module-1.0
copying hello.py -> hello_module-1.0
copying setup.py -> hello_module-1.0
creating dist
creating 'dist\hello_module-1.0.zip' and adding 'hello_module-1.0' to it
adding 'hello_module-1.0'
adding 'hello_module-1.0\hello.py'
adding 'hello_module-1.0\PKG-INFO'
adding 'hello_module-1.0\README'
adding 'hello_module-1.0\setup.py'
removing 'hello_module-1.0' (and everything under it)

 

 hello_module-1.0.zip就是生成的python模块, 解压后使用python setup.py install安装该模块。从路径可以看出,该模块安装到标准库的制定路径下。

C:\Users\23798\Desktop\desktop\my_note\python_project\mysetuptool\dist\hello_module-1.0>python setup.py install
running install
running build
running build_py
creating build
creating build\lib
copying hello.py -> build\lib
running install_lib
copying build\lib\hello.py -> C:\Python27\Lib\site-packages
byte-compiling C:\Python27\Lib\site-packages\hello.py to hello.pyc
running install_egg_info
Writing C:\Python27\Lib\site-packages\hello_module-1.0-py2.7.egg-info

现在,我们就可以打开python导入这个包了

>>> import hello
('Current time:', 'Tue Nov 22 21:28:18 2022')

 

标签:1.0,distutils,python,setup,py,module,hello,打包
From: https://www.cnblogs.com/pfeiliu/p/16916796.html

相关文章

  • Python基础之数据库:1、数据库发展史及常用数据库的介绍
    Python基础之数据库目录Python基础之数据库一、储存数据演变史1、文本文件2、软件开发目录规范3、数据库二、数据库软件应用史三、数据库的本质四、数据库的分类1、关系......
  • Python函数的参数列表
    一、函数参数的分类函数的参数分为两类:形参及实参形参:形参是在创建过程中声明的参数,如果不给形参传入特定的实参,形参就没有实际的意义实参:实参是在函数的调用过程中传......
  • Python中除了lambda函数能实现一句话程序,还有什么方式能够实现呢?
    引言我们都知道python中使用lambda函数能够实现一句话程序,一句话能实现复杂功能,是一件多么炫酷的事情.但也是有利有弊的,至少一句话代码虽然简洁,但可读性不好,毕竟现实中......
  • Python 命令行参数
    Python命令行参数参考文章:https://zhuanlan.zhihu.com/p/56922793目标:编写出可执行参数的脚本文件并打包;1.sys模块方法使用sys.argv获取执行参数;"""开发终端参......
  • 2211-22学习记录之python百分数,time模块
    百分数print('{:.0%}'.format(84/100))输出为84%以上百分数输出是使用到了字符串格式化函数format(),在其中将分数42/50作为值给传递了进去。如果将分子分母同时乘以2......
  • 2. pycharm终端提示无法加载文件 F:\Users\Administrator\PycharmProjects\python
    问题如下:终端(terminnal)遇到下面红色问题。   怎么解决??pycharm终端提示无法加载文件F:\Users\Administrator\PycharmProjects\pythonProject\venv\Scripts\activa......
  • python之路33 MySQL 1
    存取数据的演变1.文本文件文件路径不固定:C:\aaa.txtD:\bbb.txtE:\ccc.txt数据格式不统一:jason|123jason$123jason1232.软件开发目录规范规定......
  • 几句话说清python中的零宽断言
    1、所谓零宽,是指”一个字符位置,不占字符宽度“。故称为“零宽”。2、所谓的先行断言,后发断言,......等等不一而足的种种称谓,只能徒增初学者理解上的困难。其实,以正则表达式中......
  • Python中 "is" "in""=="三个的区别含义
    1."is","in","=="的意思?"is":判断两个对象的标识符(通常所说的内存地址)是否相同。"in":用于成员检测,判断一个对象是否在另一个对象里面。"==":判断内容或者地址......
  • 20221122-Python格式化字符串
    1.格式化字符串       ......