mac下的应用程序发布 及 打包(Python写的脚本,可打包第三方库)
其实这个问题在网上能搜到大把的解决方案。大家的统一答案都是
otool -L yourapp.app/Contents/MacOS/yourapp
根据输出信息在运行 install_name_tool
install_name_tool的使用方法在这里
比较复杂的是当依赖了很多第三方库,尤其是向QT这样的库的时候。打包那叫一个麻烦啊。
QT有个官方的文档告诉你如何手动一步步打包程序,还提供了一个macdepotqt这么个程序。帮你进行打包。
可是啊,macdepotqt不支持其他第三方库,也不灵活,按照官方文档的方式手动打包,坑爹啊。
说他坑爹一点都不假,当你遇到了成片的符号需要你敲命令的话,想死的心情油然而生。
那么好了。自己动手吧。这里我给出一个我写的打包的Python脚本半成品,思想跟手动敲命令是一样的,只不过用脚本实现自动化了同时递归检查并将缺少的库考到bundle目录中。脚本中针对QT的库进行打包了,如果希望把其他的依赖库也打包的话在keywordList里边添加相应的关键字就好了。希望对大家能有帮助。
- import os
- import sys
- import commands
- binaryName = "yourapp"
- bundleName = "yourapp.app"
- bundleFrameworkDir = "Contents/Frameworks/"
- bundleBinaryDir = "Contents/MacOS/"
- bundleLibraryList = [];
- systemFrameworkDir = "/Library/Frameworks/"
- keyWordList = ["Qt"]
- #add more keywords to work better
- def hasKeyWord(word):
- for it in keyWordList:
- if word.find(it) != -1:
- return True
- return False
- def findApp(name):
- return name+bundleBinaryDir+binaryName
- def getBundleDependsInfo(app):
- dependList = commands.getoutput("otool -L " + app).replace("\t","").split("\n");
- del(dependList[0])
- dependList = [item.split(" ")[0] for item in dependList if hasKeyWord(item)];
- return dependList
- def copyLibrary(base, src, dst):
- systemFullPath = src
- print "library %s depend %s" % (os.path.basename(base), os.path.basename(dst))
- if not os.path.exists(dst):
- bundleFullPath = os.path.dirname(dst)
- os.system("mkdir -p %s" % (bundleFullPath))
- os.system("cp %s %s" % (systemFullPath, bundleFullPath))
- infoList = getBundleDependsInfo(dst)
- copyDependFiles(dst, infoList)
- os.system("install_name_tool -id @executable_path/../Frameworks/%s %s" % (src, dst))
- os.system("install_name_tool -change %s @executable_path/../Frameworks/%s %s" % (src, src, base))
- def getFrameworkName(dirname):
- if dirname.find("framework") == -1:
- return
- while not dirname.endswith("framework"):
- dirname = os.path.dirname(dirname)
- return dirname
- def copyFrameworkExtDir(src):
- sysPath = systemFrameworkDir + src
- destPath = ""
- if not os.path.exists(sysPath):
- return
- frameworkPath = getFrameworkName(sysPath)
- frameWorkName = getFrameworkName(src)
- bundlePath = bundleName + "/" + bundleFrameworkDir + frameWorkName + "/"
- for it in bundleFrameworkExtDir:
- destPath = bundlePath + it
- srcPath = frameworkPath + "/" + it
- if not os.path.exists(destPath) and os.path.exists(srcPath):
- print "copying %s %s" % (frameWorkName, it)
- os.system("cp -r %s %s" % (srcPath, destPath))
- def copyFramework(base, src, dst):
- print "framework %s depend %s" % (os.path.basename(base), os.path.basename(dst))
- systemFullPath = systemFrameworkDir+src
- if not os.path.exists(dst):
- bundleFullPath = os.path.dirname(dst)
- os.system("mkdir -p %s" % (bundleFullPath))
- os.system("cp %s %s" % (systemFullPath, bundleFullPath))
- copyFrameworkExtDir(src)
- infoList = getBundleDependsInfo(dst)
- copyDependFiles(dst, infoList)
- ("install_name_tool -id @executable_path/../Frameworks/%s %s" % (src, dst))
- os.system("install_name_tool -id @executable_path/../Frameworks/%s %s" % (src, dst))
- os.system("install_name_tool -change %s @executable_path/../Frameworks/%s %s" % (src, src, base))
- def copyDependFiles(base, infoList):
- targetDir = ""
- for it in infoList:
- targetDir = bundleName + "/" + bundleFrameworkDir + it
- if it.find("framework") != -1:
- copyFramework(base, it, targetDir)
- else:
- copyLibrary(base, it, targetDir)
- def makeBundleDirs():
- os.system("mkdir -p " + bundleName + "/" + bundleFrameworkDir)
- if __name__ == "__main__":
- target = findApp(bundleName + "/")
- makeBundleDirs()
- infoList = getBundleDependsInfo(target)
- copyDependFiles(target, infoList)
http://blog.csdn.net/livemylife/article/details/7294778
mac下的应用程序发布 及 打包(Python写的脚本,可打包第三方库)的更多相关文章
- Mac下将C程序创建为动态链接库再由另一个C程序调用
写C的时候需要调用之前的一个C程序,想用动态链接库的方式.Mac下的动态链接库是dylib,与Linux下的.os或Windows下的.dll不同.由于之前没有接触过,所以翻了大量的博客,然而在编译过 ...
- 如何发布自己用python写的py模块
Python——怎么发布你的Python模块 我们在学习Python的时候,除了用pip安装一些模块之外,有时候会从网站下载安装包下来安装,我也想要把我自己编写的模块做成这样的安装包,该怎么办,如何发 ...
- Mac下修改应用程序的菜单快捷键!
点击左上角苹果按钮,系统偏好设置 > 键盘 > 快捷键 > 应用快捷键 点击右下角添加按钮,选择chrome程序,输入菜单中文名以及快捷键 1.如何用F5刷新 鼠标悬停在左上角的刷新 ...
- Mac下Homebrew将程序文件存在什么位置
一般情况是这么操作的: 1.通过brew install安装应用最先是放在/usr/local/Cellar/目录下. 2.有些应用会自动创建软链接放在/usr/bin或者/usr/sbin,同时也会 ...
- linux安装配置apk打包程序gradle+jdk+Android_sdk+python自动化编译脚本
安装gradle: 1.下载gradle包 去这里下载需要的tar.gz包:https://services.gradle.org/distributions/ 2.解压 tar zxvf gradl ...
- Mac下各种编程环境的配置问题(python java)
首先,去官网下载安装包.直接运行安装.安装完成后,启动器中会多两个应用程序IDLE和Python Launcher. 如果,你习惯在IDLE,直接运行即可. 但你在Terminal中运行python3 ...
- 在mac下使用python抓取数据
2015已经过去,这是2016的第一篇博文! 祝大家新年快乐! 但是我还有好多期末考试! 还没开始复习,唉,一把辛酸泪! 最近看了一遍彦祖的文章叫做 iOS程序员如何使用Python写网路爬虫 所以自 ...
- Python将自己写的模块进行打包
将项目打包成模块的想法来自于flask文档教程,这不是在PyCon上和阿明合了照嘛,这不得多看看人家的东西.有兴趣的可以看看文档的项目可安装化部分,作者将flask项目打包成一个包,使其可以再任何地方 ...
- mac下git+maven+jenkins自动打包发布
随着springboot+springcloud(dubbo)越来越多人使用,流行的微服务的概念越来越深入人心.分布式部署越来越复杂,给手动发布带来很大工作量.为了方便前期测试和后期线上部署更新,可使 ...
随机推荐
- win7如何快速设置开机启动项?
添加开机启动项方法: 找到windows开始菜单->所有程序->启动,右键打开, 进入C:\Users\Ocean\AppData\Roaming\Microsoft\Windows\St ...
- [LeetCode]题解(python):024-Swap Nodes in Pairs
题目来源: https://leetcode.com/problems/swap-nodes-in-pairs/ 题意分析: 给定一个链表,每两个相邻节点就行交换.比如1->2->3-&g ...
- 深入浅出—JAVA(9)
9.构造器与垃圾收集器 调用父类构造函数的唯一方法是调用super().
- 转: seajs手册与文档之 -- require规则
require 规则 正确拼写 不要修改 使用直接量 动态依赖的小提示 书写规则 使用 SeaJS 书写模块代码时,需要遵循一些简单规则: 1. 正确拼写 在模块代码中,第一个参数 必须 命名为 re ...
- java学习之IO字符流
package com.io; import java.io.*; /** * 文件字符流的读取 * @author ganhang * */ public class FileReaderDemo ...
- CUDA samples 第三章 sample reference 概况
示例代码分为下列几类: 1. Simple Reference 基础CUDA示例,适用于初学者, 反应了运用CUDA和CUDA runtime APIs的一些基本概念. 2. Utilitie ...
- redhat6.3安装matlab运行时MCR7.8,初步测试ok
redhat6.3安装完matlab2008a后在目录$MATLAB_HOME/toolbox/compiler/deploy/glnxa64中有MCRInstaller.bin 使用这个安装MCR即 ...
- 全局获取Context的技巧
全局获取Context的技巧 在android开发中,非常多地方都要用到Context上下文这个类对象,比方:弹出 Toast 的时候须要.启动活动的时候须要.发送广播的时候须要.操作数据库的时候须要 ...
- uva 10599 - Robots(II) (dp | 记忆化搜索)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- 使用ORACLE SQL Tuning advisor快速优化低效的SQL语句
ORACLE10G以后版本的SQL Tuning advisor可以从以下四个方面给出优化方案 (1)为统计信息丢失或失效的对象收集统计信息 (2)考虑优化器的任何数据偏差.复杂谓词或失效的统计信 ...