赞
踩
心得: 过去的几个月里,有忙有闲,慢慢的忘记了自己的成长,在忙碌中使得自己成长变得缓慢,之后的每一天加油,保持自律,保持学习积极的态度。
在多人协作的项目中,往往又可能会依赖他人库,或者别人调用你的代码,或者服务器部署代码,环境配置等等,搭建环境往往需要花费很长的时间来,所以很有必要对我们的完成的项目打出一个外包,别人使用时,往往只需要一键安装,比如已经可以使用的sklearn包,numpy 等等 pip install sklearn
,安装使用都很方便。
安装wheel
pip install wheel
新建项目目录:
setup.py
from setuptools import setup, find_packages
setup(
name='printtest',
version='1.0',
packages=find_packages(),
)
test.py
def test123():
print('print test')
return "hello world"
开始打包,切换到terminal 执行python setup.py bdist_wheel
同级目录下会生成打包后的文件:
lib下是安装后packages显示结构,dist下的.whl可以直接pip install dist/..whl
进行安装
安装调用:
导入的是以打包前的目录结构进行导入调用,此项目是pro/test.py test123() 函数
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包
setup.py
from setuptools import setup, find_packages setup( name='printtest', version='1.0', description='hello world', license='Apache', author="tian", author_email="tianjian361@163.com", include_package_data=True, # 自动包含包内所有受版本控制(cvs/svn/git)的数据文件 packages=find_packages(include=["pro", "pro.*"]), # 需要处理的包目录(包含__init__.py的文件夹)和setup.py同一目录 # 下搜索各个含有 init.py的包,也可以指定find_packages(),代表打包所有文件 package_data={'': ['*.json', '*.csv']}, # 也可以用做打包非py文件,可以使用正则匹配的方式,但文件目录必须包含__init__.py data_files=[('pro', ['pro/data/t.json', 'pro/data/t.csv'])], # 打包时非py文件存在时,必须得具体指定某个文件的相对路径 python_requires='>=3.6.0', install_requires=['decorator==4.3.0'], # 定义依赖哪些模块 如果不存在自动下载,存在则跳过 zip_safe=False, extras_require={} )
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。