如何在Travis CI上构建MacOSX可执行文件?

2024-05-14 18:53:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个只依赖wxPython的小python程序。我在Linux上开发了这个程序,并成功地使用wine on Travis CI(github上的seguid_计算器)设置了windows可执行文件的自动构建。在

我的解决方案是将最近发布的wine和Pyinstaller结合起来。在

我想为MacOS做类似的事情。我知道Travis上也有一个MacOSX构建环境。我对MacOSX操作系统没有任何经验,而且我也没有Mac电脑。我知道你可以用“自制软件”安装第三方软件包

我想做什么?一个例子特拉维斯·伊梅尔文件太好了!在

谢谢你的意见, /比约恩

*编辑*

我创建了一个只打开窗口的wxpython应用程序示例。它位于https://github.com/BjornFJohansson/macapp。 我用的是。特拉维斯·伊梅尔在下面生成不工作的可执行文件。在

os:
- osx
language: objective-c
python:
- '2.7'
before_install:
- brew update
- brew outdated xctool || brew upgrade xctool
- brew install python
- brew install wxpython
- pip install pyinstaller
- pyinstaller --noconsole --onefile hw.py
- ls
- ls dist/
- hdiutil create dist/hw.dmg -srcfolder dist/ -ov
install: true
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: VK1oVWQCRomgcFNVua00B3YSsotezzU1p6/fh73/0vwQFzVMolVnAsnfSq6EAwIcJvakU0TI9pqZR+0S3PKnUs+Kn3Ar8OwQ88t2azZNwewBfKua3tM2/7BF4y7O0gOtN1F29Yxyu0zPInIVY17BqGygibQ1kthBTm+tj3YyNW8=
  file: 
    - "dist/hw"
    - "dist/hw.dmg"
  on:
    tags: true
    all_branches: true
    repo: BjornFJohansson/macapp

基本上,我首先更新xtools(我看到很多这样做,所以我决定也这么做)。然后我brew安装python和wxpython。然后我pip安装pyinstaller。我使用pyinstaller命令生成一个可执行文件(hw)和一个“硬件应用程序“文件夹位于./dist

我没有部署.app文件夹,所以我用hdiutil创建了一个.dmg。 然后部署到github版本。在

有人能告诉我这个装置有什么问题吗?在

travis日志可以在这里找到:https://travis-ci.org/BjornFJohansson/macapp


Tags: install程序githubtrue可执行文件ondistwxpython
3条回答

你不需要os:部分。在

我在使用Travis CI在macosx上部署wxPython应用时也遇到了类似的问题。不幸的是,我的设置有点复杂,但它可能有助于解决您的问题。在

我用康达来建造一切。在

我的travis配置:

# Mac OS X Python build
language:
- objective-c
python:
- "2.7"
install:
# install python via brew
- brew install python
# make brews python the system default
- brew link  overwrite python
- which python
- python  version
# pip init
- pip install  upgrade pip
# use anaconda
- pip install conda
- conda init
- conda install  yes matplotlib
- conda install  yes scipy numpy=1.8
- conda install  yes 'numpy<1.9.0'
- conda install  yes wxpython
# final pip installs
- pip install cython
- pip install wheel
- pip install sympy
- pip install git+git://github.com/pyinstaller/pyinstaller.git@779d07b236a943a4bf9d2b1a0ae3e0ebcc914798
# show packages
- pip freeze
# build extensions
- python setup.py develop
script:
# Create wheel pacakge
- python setup.py bdist_wheel
# Create binary
- ./freeze_pyinstaller/macOSx_bundle_script.sh
before_deploy:
  - export RELEASE_PKG_FILEA=$(ls ./dist/*bin.zip)
  - export RELEASE_PKG_FILEB=$(ls ./dist/*app.zip)
  - export RELEASE_PKG_FILEC=$(ls ./dist/*.whl)
  - echo "deploying $RELEASE_PKG_FILEA to GitHub releases"
  - echo "deploying $RELEASE_PKG_FILEB to GitHub releases"
  - echo "deploying $RELEASE_PKG_FILEC to GitHub releases"
# This section was created with
# sudo apt-get install ruby1.9.1-dev
# sudo gem install travis
# travis setup releases
deploy:
  provider: releases
  api_key:
    secure: gQu6BKSo5sucrieOvyLz/kn5Ai+vrnXK6Kdm+WMqzXE6keE0LzujXOHWQX2G2EBl1NCjzvt3HrEvJqwGEjLbduJBBPBHaOy71AfKuHaxRQPlFWMLn2iAVVval3q7xU4kEfjAdS50WmARqh6sT7gMj+pHpg1e3pz1SxybOeC40+k=
  skip_cleanup: true
  # Allow
  file_glob: true
  file: 
    - "${RELEASE_PKG_FILEA}"
    - "${RELEASE_PKG_FILEB}"
    - "${RELEASE_PKG_FILEC}"
  on:
    tags: true
    repo: paulmueller/PyCorrFit

我在创建一个应用程序时遇到了问题(可能是因为我古老的构建系统)。因此,我不得不用包含以下内容的脚本替换app文件夹中的二进制文件:

^{2}$

其中MYAPP是应用程序的名称,我以前曾将app文件夹中的二进制文件重命名为MYAPP.bin。在

当应用程序启动时,终端打开并启动二进制文件。在

以下是使用Travis构建的版本:

https://github.com/paulmueller/PyCorrFit/releases/tag/0.8.7travis2

这是一个基于旧MacBook的工作版本:

https://github.com/paulmueller/PyCorrFit/releases/tag/0.8.7

在使用Travis构建的版本中,存在某种wxpython错误。我没有最新OSx的Mac电脑。或许你能帮上忙。在

This声明他们当前不接受新的“多操作系统”请求,因此在升级Travis CI之前,您无论如何都无法为os-X构建。在

一般来说,您需要接受多操作系统,然后将os: os-x添加到.travis.yml文件中(可能在一个分支上),然后查找如何在os-X中设置python、pyinstaller和wxpython—在这方面,所有3个的主页都非常有用。在

它不起作用的原因是通过自制程序安装的wxPython版本不是32位的。您需要从wxPython主页安装dmg。我在那里找到了一个脚本:https://github.com/ayufan/travis-osx-vm-templates/blob/master/scripts/packages.sh

我把你的例子分成两部分,并设法使它运行(https://github.com/paulmueller/macapp/releases)。在

一。特拉维斯·伊梅尔现在看起来像这样:

language: objective-c
python:
- '2.7'
before_install:
- which python
- brew install python  universal  framework
- brew install wget
- which python
- export VERSIONER_PYTHON_PREFER_32_BIT=yes
- defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
- which python
- python  version
# https://github.com/Homebrew/homebrew/issues/34470
#- arch -i386 brew install wxpython  universal
- mkdir dl
- cd dl
- wget http://downloads.sourceforge.net/wxpython/wxPython3.0-osx-3.0.2.0-cocoa-py2.7.dmg
- ls
- cd ..
- sudo ./packages.sh
- arch -i386 python -c "import wx; print wx.__version__"
- arch -i386 pip install pyinstaller
- arch -i386 pyinstaller  noconsole  onefile hw.py
- ls
- hdiutil create dist/hw.dmg -srcfolder dist/ -ov
- zip -r dist/hw.zip dist/hw.app
- ls dist/
install: true
deploy:
  provider: releases
  skip_cleanup: true
  api_key:
    secure: KjdN4hSHWU3ZDg6lpDNMB2we9jLayM9C8pwyQrV/Xzq8HNH5eNHP8ScI64tvnS0yJegOXnHFwUhUrkMtEs3X29TKrom+8tJ5E52IdBO7xO8fqOfeugC2239vLzc3tNI6RJX/K7CZTsSRu5U++1RJVgcWYjrCln87DuXG+HZRdOI=
  file: 
    - "dist/hw.dmg"
    - "dist/hw.zip"
  on:
    tags: true
    all_branches: true
    repo: paulmueller/macapp

相关问题 更多 >

    热门问题