Application publishing and packaging under Mac (Python-written script, can be packaged with third party libraries)

Source: Internet
Author: User
Tags python script

In fact, this problem can find a lot of solutions on the Internet. Everyone's unified answer is

Otool-l Yourapp.app/contents/macos/yourapp

Run Install_name_tool According to the output information

How to use the Install_name_tool here

It's more complicated when you rely on a lot of third-party libraries, especially for libraries like Qt. Packing that call a trouble.

QT has an official document that tells you how to manually package a program, and also provides a MACDEPOTQT such a program. To help you pack.

However, MACDEPOTQT does not support other third-party libraries, and is not flexible, according to the official document of the way of manual packaging, Pit dad ah.

Say he is not a fake father, when you meet the symbols need you to knock orders, want to die in the mood arises spontaneously.

That's good. Do it yourself. Here I give a packaged Python script I write semi-finished, the idea is the same as the manual Knock Command, but with the script to automate the simultaneous recursive check and the missing library to the bundle directory. The library for QT is packaged in the script, and if you want to pack other dependent libraries, add the corresponding keywords in the keywordlist. Hope to be helpful to everyone.

[Python]View PlainCopy
  1. Import OS
  2. Import Sys
  3. Import commands
  4. Binaryname = "YourApp"
  5. Bundlename = "Yourapp.app"
  6. Bundleframeworkdir = "contents/frameworks/"
  7. Bundlebinarydir = "contents/macos/"
  8. Bundlelibrarylist = [];
  9. Systemframeworkdir = "/library/frameworks/"
  10. KeywordList = ["Qt"]
  11. #add more keywords to work better
  12. def haskeyword (word):
  13. For it in keywordlist:
  14. if Word.find (IT)! =-1:
  15. return True
  16. return False
  17. def findapp (name):
  18. return Name+bundlebinarydir+binaryname
  19. def getbundledependsinfo (APP):
  20. Dependlist = Commands.getoutput ("otool-l" + app). Replace ("\T", ""). Split ("\ n");
  21. del (dependlist[0])
  22. Dependlist = [Item.split ("") [0] for item in dependlist if Haskeyword (item)];
  23. return dependlist
  24. def copylibrary (base, SRC, DST):
  25. Systemfullpath = src
  26. print "library%s depend%s"% (Os.path.basename (base), Os.path.basename (DST))
  27. If not os.path.exists (DST):
  28. Bundlefullpath = Os.path.dirname (DST)
  29. Os.system ("mkdir-p%s"% (Bundlefullpath))
  30. Os.system ("cp%s%s"% (Systemfullpath, bundlefullpath))
  31. Infolist = Getbundledependsinfo (DST)
  32. Copydependfiles (DST, infolist)
  33. Os.system ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
  34. Os.system ("Install_name_tool-change%s @executable_path/.. /frameworks/%s%s "% (src, src, base))
  35. def getframeworkname (dirname):
  36. if Dirname.find ("framework") = =-1:
  37. return
  38. While not Dirname.endswith ("framework"):
  39. DirName = Os.path.dirname (dirname)
  40. return dirname
  41. def copyframeworkextdir (SRC):
  42. Syspath = Systemframeworkdir + src
  43. DestPath = ""
  44. If not os.path.exists (syspath):
  45. return
  46. Frameworkpath = Getframeworkname (Syspath)
  47. FrameworkName = Getframeworkname (src)
  48. Bundlepath = bundlename + "/" + Bundleframeworkdir + frameworkname + "/"
  49. For it in bundleframeworkextdir:
  50. DestPath = Bundlepath + it
  51. Srcpath = Frameworkpath + "/" + It
  52. If not os.path.exists (destpath) and os.path.exists (srcpath):
  53. print "copying%s%s"% (FrameworkName, it)
  54. Os.system ("cp-r%s%s"% (Srcpath, destpath))
  55. def copyframework (base, SRC, DST):
  56. Print "Framework%s depend%s"% (Os.path.basename (base), Os.path.basename (DST))
  57. Systemfullpath = Systemframeworkdir+src
  58. If not os.path.exists (DST):
  59. Bundlefullpath = Os.path.dirname (DST)
  60. Os.system ("mkdir-p%s"% (Bundlefullpath))
  61. Os.system ("cp%s%s"% (Systemfullpath, bundlefullpath))
  62. Copyframeworkextdir (SRC)
  63. Infolist = Getbundledependsinfo (DST)
  64. Copydependfiles (DST, infolist)
  65. ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
  66. Os.system ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
  67. Os.system ("Install_name_tool-change%s @executable_path/.. /frameworks/%s%s "% (src, src, base))
  68. def copydependfiles (Base, infolist):
  69. TargetDir = ""
  70. For it in infolist:
  71. TargetDir = bundlename + "/" + Bundleframeworkdir + it
  72. if It.find ("framework")! =-1:
  73. Copyframework (base, it, TargetDir)
  74. Else:
  75. Copylibrary (base, it, TargetDir)
  76. Def makebundledirs ():
  77. Os.system ("mkdir-p" + bundlename + "/" + Bundleframeworkdir)
  78. if __name__ = = "__main__":
  79. target = Findapp (Bundlename + "/")
  80. Makebundledirs ()
  81. Infolist = Getbundledependsinfo (target)
  82. Copydependfiles (target, infolist)

http://blog.csdn.net/livemylife/article/details/7294778

Application publishing and packaging under Mac (Python-written script, can be packaged with third party libraries)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.