关于python程序打包的介绍就不多说了,大部分的python基础书上都有介绍。这里就直接演练。
只是一个简单的demo,一个demo项目中,有一个hello文件,文件中有一个函数hello,函数的作用是读取testdd.txt文件中的数据然后输出。
这个项目中还有其他的一些东西,以演示打包。
整个项目结构如下:
"-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"
>
singledemo
demo
model
init.py
entity.py
static
test.txt
hello.py
MANIFEST.in
setup.py
hello.py中的代码:
"-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"
>
def hello():
f = open('testdd.txt', 'r')
content = f.read()
f.close()
print content
setup.py中的代码如下:
"-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"
>
coding:utf-8
'''
'''
import os
import sys
from setuptools import setup, find_packages
setup(
name =
"demo"
,
version =
"0.0.1"
,
packages = find_packages(),
include_package_data = True,
entry_points = {
'console_scripts' : [
'demo = demo.hello:hello'
],
},
package_data = {
'demo':['*.txt']
},
author =
"the5fire"
,
author_email = '嘻嘻嘻嘻嘻嘻嘻@email.com',
url =
"http://www.the5fire.com"
,
description = 'a demo for setuptools',
)