您的位置:首页 > 编程语言 > Python开发

[Python] Python2.7发布成EXE

2018-03-21 16:50 447 查看

示例代码

代码来源:http://blog.csdn.net/summer_dew/article/details/79634944

文件名:draw_line.py

# -*- coding: utf-8 -*-

from PIL import Image
from PIL import ImageDraw
import os

# input_img = r'E:\user\Desktop\tmp.png'
input_img = raw_input("Enter the full path of the file:\n")
input_color = raw_input("Enter grid color, separated by Spaces:\n")
r,g,b = input_color.split(" ")
r = int(r)
g = int(g)
b = int(b)

(filepath,filename) = os.path.split(input_img)
img = Image.open(input_img)
img_d = ImageDraw.Draw(img)
x_len, y_len = img.size
x_step = x_len/50
y_step = y_len/30
for x in range(0, x_len, x_step):
img_d.line(((x, 0), (x, y_len)), (r, g, b))
for y in range(0, y_len, y_step):
j = y_len - y - 1
img_d.line(((0, j), (x_len, j)), (r, g, b))
img.save(os.path.join(filepath,"grid_"+filename) )

cnt = 1
for i in range(0,x_len,x_step):
img_d.text((i,y_len-y_step), str(cnt).encode("utf8"),fill=(255,0,0))
cnt+=1
cnt = 1
for j in range(y_step,y_len,y_step):
z = y_len - j
img_d.text((0,z), str(cnt).encode("utf8"),fill=(255,0,0) )
cnt+=1
img.save(os.path.join(filepath, "grid_geocoding_"+filename))

print "compete"
input()


PyInstaller

使用pip安装:pip2 install Pyinstaller

py2exe

下载安装py2exe:http://www.py2exe.org/

编写代码

#!/usr/bin/python
from distutils.core import setup
import py2exe
import os,sys

CurrentPath = os.path.dirname(sys.argv[0])
setup(console=[str(CurrentPath)+'draw_line.py']) #filename


切换命名行,运行

cd C:\Python27\toExe
python2 setup.py py2exe


生成结果:



exe结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python exe