一.setuptools

- 官方文档: Building and Distributing Packages with Setuptools
- 中文文档: Python包管理工具setuptools详解

1.使用过程

编辑: 先在项目主目录下编辑setup.py,
打包: python setup.py sdist
安装: sudo python setup.py install (--record files.txt)
卸载: sudo cat files.txt | sudo xargs rm -rf

2. setuptools工具的setup.py的模板

from setuptools import setup, find_packages
setup(
name="HelloWorld",
version="0.1",
packages=find_packages(),
scripts=['say_hello.py'], # Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires=['docutils>=0.3'], package_data={
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.rst'],
# And include any *.msg files found in the 'hello' package, too:
'hello': ['*.msg'],
}, # metadata for upload to PyPI
author="Me",
author_email="me@example.com",
description="This is an Example Package",
license="PSF",
keywords="hello world example examples",
url="http://example.com/HelloWorld/", # project home page, if any # could also include long_description, download_url, classifiers, etc.
)

声明依赖包的语法:

This syntax consists of a project’s PyPI name, optionally followed by a comma-separated list of “extras” in square brackets, optionally followed by a comma-separated list of version specifiers.

A version specifier is one of the operators <, >, <=, >=, == or !=, followed by a version identifier.

Tokens may be separated by whitespace, but any whitespace or nonstandard characters within a project name or version identifier must be replaced with -.

其它例子:

docutils >= 0.3

# comment lines and \ continuations are allowed in requirement strings
BazSpam ==1.1, ==1.2, ==1.3, ==1.4, ==1.5, \
==1.6, ==1.7 # and so are line-end comments PEAK[FastCGI, reST]>=0.5a4 setuptools==0.5a7

详情可参考官方说明:Declaring Dependencies

二.Python项目的打包、发布和部署的常用方法比较

1. distutils - python自带的基本安装工具, 适用于非常简单的应用场景使用, 不支持依赖包的安装
  通过distutils来打包,生成安装包,安装python包等工作,需要编写名为setup.py python脚本文件。 2. setuptools - 针对 distutils 做了大量扩展, 尤其是加入了包依赖机制。不支持python3,安装完setuptools后会有easy_install 3. distribute - 类似于setuptools,支持python3,安装完distribute后会有easy_install。 4. easy_install - setuptools 和 distribute 自带的安装脚本, 也就是一旦setuptools或distribute安装完毕, easy_install 也便可用了。 5. pip - 目标是取代easy_install。easy_install 有很多不足: 安装事务是非原子操作, 只支持 svn, 没有提供卸载命令, 安装一系列包时需要写脚本; pip 解决了以上问题, 已俨然成为新的事实标准, virtualenv 与它已经成为一对好搭档; 6. distutils2 - setuptools 和 distribute 的诞生是因为 distutils 的不济, 进而导致目前分化的状况。它将成为 Python 3.3 的标准库 packaging , 并在其它版本中以distutils2 的身份出现; 换句话说, 它和 pip 将联手结束目前混乱的状况。 7. virtualenv - 用来创建隔离的python环境,处理python环境的多版本和模块依赖。

常识
1. sudo apt-get install 安装的package存放在 /usr/lib/python2.7/dist-packages目录中
2. pip 或者 easy_install安装的package存放在/usr/local/lib/python2.7/dist-packages目录中
3. 手动从源代码安装的package存放在site-packages目录中

参考:

python项目打包发布总结

[Python] 项目打包发布的更多相关文章

  1. [转]Python依赖打包发布详细

    Python依赖打包发布详细   http://www.cnblogs.com/mywolrd/p/4756005.html 将Python脚本打包成可执行文件   Python是一个脚本语言,被解释 ...

  2. Java学习之道:Java项目打包发布

    Java项目打包发布 如果只想发布为一个可执行的jar包,使用eclipse的Export功能就可以了 使用eclipse的Export功能,将项目中的所有package打包为一个pet.jar文件, ...

  3. VS2010下创建的VB.NET项目打包发布安装包的流程

    VS2010下创建的VB.NET项目打包发布安装包的流程 参考:http://blog.csdn.net/liuyanlinglanq/article/details/8609675  关于relea ...

  4. 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片)

    解决 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片) 1.当我们写了一个Python的项目时,特别是一个GUI项目,我们特备希望它能成为一个在Windows系统可执行的EXE文件 ...

  5. SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.了解SpringBoot的基本概念 2.具体内容 在之前所建立的 SpringBoot 项目只是根据官方文档实现的一个基础程 ...

  6. Java项目打包发布

    Java项目打包发布 如果只想发布为一个可执行的jar包,使用eclipse的Export功能就可以了 使用eclipse的Export功能,将项目中的所有package打包为一个pet.jar文件, ...

  7. Vue项目打包发布后CSS中的背景图片不显示

    相信有很多同学在学习vue的刚开始都遇到过项目打包发布后发现CSS中的背景图片不显示,具体如何解决只需要更改bind的配置即可 修改 build/utils.js 中的 generateLoaders ...

  8. Python依赖打包发布详细

    http://www.cnblogs.com/mywolrd/p/4756005.html 将Python脚本打包成可执行文件   Python是一个脚本语言,被解释器解释执行.它的发布方式: .py ...

  9. 利用pyinstaller将python脚本打包发布

    之前写了一个小工具,将excel配置表转换为json.xml.lua等配置文件.最近在学习egret,正好需要转换配置文件,刚好就用上了.然而当我想把工具拷到工作目录时,就发愁了.之前我为了方便扩展, ...

随机推荐

  1. 再也不学AJAX了!(一)AJAX概述

    "再也不学AJAX了"是一个与AJAX主题相关的文章系列,包含以下三个部分的内容: AJAX概述:主要回答"AJAX是什么"这个问题: 使用AJAX:介绍如何通 ...

  2. keras安装配置指南【linux环境】【转】

    本文转载自:https://keras-cn.readthedocs.io/en/latest/for_beginners/keras_linux/#kerasmnist 本教程不得用于任何形式的商业 ...

  3. this 的理解

    function foo(num){ console.log("foo:",+num); this.count++}foo.count =0for (var i=0; i<1 ...

  4. visual studio中添加existing web site, website名字附带数字

    用visual studio直接运行website项目 发现有一个conifg文件的配置,路径是solution同级目录下的.vs/config文件夹下有一个applicationhost.confi ...

  5. C语言一些总结

    预处理#include<stdio.h>:头文件. stdio.h 标准输入输出. string.h 字符串预处理,. int main()主函数,返回的是int整型, return 0; ...

  6. C#之多线程

    多线程在C#中使用得非常频繁,线程之间的充分利用显得尤为重要,一般的写法都是得不到充分利用资源,本人针对多线程写了一种方法,可以充分利用资源,保证每次同时启动10条线程,现在执行完马上再启动一条,总之 ...

  7. 从Github上轻松安装R包—githubinstall包--转载

    1.综述 越来越多的R包正在由世界上不同的人所创建,其中一部分原因是devtools包使得开发R包1变得更加简单.devtools包不仅让开发R包变得简单,而且用于分发R包. 当开发者发布一个R包的时 ...

  8. mac配置jenkins遇到的问题及解决办法

    写这篇博客的时候,我暂时放弃了mac配置jenkins,先记着遇到的坑吧.虽然无数次想砸电脑,但是回头想想,对于经常用windows系统和接触过linux的测试的我来说,这也是个熟悉mac系统的机会. ...

  9. Session存储

    session其实分为服务器端Session和客户端Session. 当用户首次与Web服务器建立连接的时候,服务器会给用户分发一个sessionid作为标识.用户每次提交页面,浏览器都会把这个ses ...

  10. [spring]xml配置文件中bean属性的两种写法(p:configLocation <=> <property name="configLocation"/>)

    1.当作bean节点的属性:p:configLocation: <!-- mybatis文件配置,扫描所有mapper文件 --> <bean id="sqlSession ...