setup.py应用场合

网上见到其他人这样介绍:

假如我在本机开发一个程序,需要用到python的redis、mysql模块以及自己编写的redis_run.py模块。我怎么实现在服务器上去发布该系统,如何实现依赖模块和自己编写的模块redis_run.py一起打包,实现一键安装呢?同时将自己编写的redis_run.py模块以exe文件格式安装到python的全局执行路径C:\Python27\Scripts下呢?在这种应用场景下,pip工具似乎派不上了用场,只能使用python的构建工具setup.py了,使用此构建工具可以实现上述应用场景需求,只需在 setup.py 文件中写明依赖的库和版本,然后到目标机器上使用python setup.py install安装。

可以看到其目的就是方便我们安装代码:可以一体化的安装依赖包,并记录生成包相关信息,方便大规模部署,故对于开发者而言,编写python的第三方库,最重要的事情之一就是编写setup.py了。

使用setup例子

我们建立一个名为demo的空白文件夹,在里面创建setup.py文件,录入如下代码:

from setuptools import setup, find_packages
setup(
name = "demo",
version = "0.1",
packages = find_packages(),
)

运行命令:

python setup.py bdist_egg

此时查看目录树:

│  setup.py

├─build
│  └─bdist.win-amd64
├─demo.egg-info
│      dependency_links.txt
│      PKG-INFO
│      SOURCES.txt
│      top_level.txt

└─dist
        demo-0.1-py3.6.egg

其中dist目录下即为打包好的egg文件,可以将尾缀改为zip并解压,内部是一系列自动生成的文件,可以自行查阅功能,

│  demo-0.1-py3.6.zip

└─EGG-INFO
        dependency_links.txt
        PKG-INFO
        SOURCES.txt
        top_level.txt
        zip-safe

如果我们的生成命令使用的是:

python setup.py sdist

生成的将会是tar.gz文件,解压后直接包含setup.py文件,我们使用python setup.py install运行该文件可以直接将包拷贝到python工作目录下,方便直接调用。

在项目Mask_RCNN中,我们最终可以在anaconda目录中找到如下文件,

其对应的安装选项如下,可以一窥setup的效用,

setup(
name='mask-rcnn',
version='2.1',
url='https://github.com/matterport/Mask_RCNN',
author='Matterport',
author_email='waleed.abdulla@gmail.com',
license='MIT',
description='Mask R-CNN for object detection and instance segmentation',
packages=["mrcnn"], # setup.py同级目录下文件夹mrcnn中含有__init__.py文件
install_requires=install_reqs,
include_package_data=True,
python_requires='>=3.4',
long_description="""This is an implementation of Mask R-CNN on Python 3, Keras, and TensorFlow.
The model generates bounding boxes and segmentation masks for each instance of an object in the image.
It's based on Feature Pyramid Network (FPN) and a ResNet101 backbone.""",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Image Recognition",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Scientific/Engineering :: Image Segmentation",
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
keywords=["image instance segmentation object detection mask rcnn r-cnn tensorflow keras", ]
)

其他资料

官方文档:Writing the Setup Script

Python 库打包分发(setup.py 编写)简易指南

关于python中的setup.py

『Python』setup.py简介的更多相关文章

  1. python 利用 setup.py 手动安装第三方类库

    python 利用 setup.py 手动安装第三方类库 由于我在mac使用时,装了python3,默认有python2的环境,使用 pip 安装第三方类库时,老是安装到 python2的环境上: 在 ...

  2. python 利用 setup.py 手动安装django_chartit

    手动安装django_chartit库 1 下载压缩包 2 解压到python安装目录下,文件夹名为django_chartit,并检查文件夹下是否有setup.py文件 3 在cmd中进入djang ...

  3. python 使用 setup.py 方式安装及包的卸载

     安装:         可通过 --home 或 --prefix 指定安装目录 --prefix=xx/xxx    选择安装目录 --record files.txt   记录所有安装文件的路径 ...

  4. python安装setup.py问题

    一:python下setuptools安装( No module named setuptools 解决方案) 1. 下载:在它的官网可以下载到安装包:https://pypi.python.org/ ...

  5. Python中setup.py一些不为人知的技巧

    http://python.jobbole.com/80912/ 在我开始之前,我想先说清楚我将要解释的是些“窍门”.他们不是“最好的做法”,至少在一种情况下是不可取的. 说到不可取的做法,我会适时写 ...

  6. python带setup.py的包的安装

    如psutil-4.2.0.tar.gz tar -zxvf psutil-4.2.0.tar.gz psutil-4.2.0 cd psutil-4.2.0 sudo python setup.py ...

  7. python 通过setup.py安装和卸载python软件包

    安装:sudo python setup.py install 卸载:sudo python setup.py install --record log sudo cat log | sudo xar ...

  8. python的setup.py文件

    最近工作需要,用Cython写了*.pyx扩展,并将其编译成C文件,最后转换为so扩展,供python引用使用 distutils 编译,建立一个setup.py 的脚本from distutils. ...

  9. python的setup.py文件及其常用命令

    编写setup.py文件,获取帮助:python setup.py --help-commands [python]  Standard commands:    build             ...

随机推荐

  1. FAQ Flyway

    https://flywaydb.org/documentation/faq What is the best strategy for dealing with hot fixes? You hav ...

  2. 【#和$】MyBatis中#和$的区别

    一.结论 #{}:占位符号,好处防止sql注入 ${}:sql拼接符号 二.具体分析 动态 SQL 是 mybatis 的强大特性之一,也是它优于其他 ORM 框架的一个重要原因.mybatis 在对 ...

  3. (zhuan) Where can I start with Deep Learning?

    Where can I start with Deep Learning? By Rotek Song, Deep Reinforcement Learning/Robotics/Computer V ...

  4. [LightOJ 1370] Bi-shoe and Phi-shoe(欧拉函数快速筛法)

    题目链接: https://vjudge.net/problem/LightOJ-1370 题目描述: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. 知识点 ...

  5. Jenkins-Publish HTML reports

    创建job:testreport 在job中添加: 在Jenkins服务器上: 创建目录: .jenkins/jobs/{job名称}/workspace/htmlreports    注:此处job ...

  6. algorithm.sty not found error in LaTeX 解决方法

    参考: algorithm.sty not found error in LaTeX algorithm.sty not found error in LaTeX 解决方法 错误日志: LaTeX E ...

  7. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  8. 2017-2018-2 20165306 实验四《Android开发基础》实验报告

    实验四<Android开发基础>实验报告 实验报告封面 实验内容 Android程序设计-1 实验要求: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java ...

  9. python爬虫训练——正则表达式+BeautifulSoup爬图片

    这次练习爬 传送门 这贴吧里的美食图片. 如果通过img标签和class属性的话,用BeautifulSoup能很简单的解决,但是这次用一下正则表达式,我这也是参考了该博主的博文:传送门 所有图片的s ...

  10. springboot整合druid数据库连接池并开启监控

    简介 Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2 ...