python 二进制编译_python项目二进制打包脚本

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

"""

@File    : publish_pyc.py

@Time    : 2019/10/26 17:25

@Author  : gaobo

@Description: publish_pyc

注:将此脚本拷贝到项目的根目录下

"""

import os

import shutil

from py_compile import compile

def publish_pyc():

path = os.path.dirname(os.path.abspath(__file__))

publish_pyc_file = os.path.join(path, 'publish')

if not os.path.exists(publish_pyc_file):

os.makedirs(publish_pyc_file)

path_index = len(path)

for parent, dirname, filename in os.walk(path):

new_parent1 = parent[path_index+1:]

new_parent2 = os.path.join(path, 'publish')

new_parent = os.path.join(new_parent2, new_parent1)

if parent[:path_index+8] == publish_pyc_file:

continue

else:

if not os.path.exists(new_parent):

os.mkdir(new_parent)

for cfile in filename:

fullname = os.path.join(parent, cfile)

if cfile[-3:] == '.py':

try:

pyc_name = cfile[:-3] + ".pyc"

if compile(fullname, cfile=os.path.join(new_parent, pyc_name)):

print("文件%s编译成功" % fullname)

else:

print("文件%s编译失败" % fullname)

except:

print("无法编译文件:%s" % fullname)

else:

shutil.copy(fullname, new_parent)

print("拷贝文件---》"+fullname+"至---》"+new_parent)

if __name__ == '__main__':

publish_pyc()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值