【问题标题】:The application “ ” can’t be opened. After extracting using zipfile in python macos应用程序“ ”无法打开。在 python macos 中使用 zipfile 解压后
【发布时间】:2018-08-22 11:04:47
【问题描述】:

在使用 python 从服务器拉取构建然后提取后,我无法启动应用程序。我收到错误消息“应用程序“无法打开”我在内容中的可执行文件上尝试了 chmod +x,然后应用程序启动到黑屏。相同的代码似乎在 Windows 上为我工作。有任何想法吗?

这是我的代码

import glob, shutil, os, zipfile, send2trash

source = '/my/build/location'
target = '/my/directory'

def getLatestBuild(source, target):
    list_of_files = glob.glob(source + '/*.zip')
    latest_file = max(list_of_files, key = os.path.getctime)
    print(latest_file + '\n\nDownloading\n\n----------')
    shutil.copy(latest_file, target)
    return latest_file

def change_dir(latest_file):
    directory, file = os.path.split(latest_file)
    target_build = os.path.join(target, file)
    return target_build

def extractZip(target_build):
    zip_ref = zipfile.ZipFile(target_build, 'r')
    print('Unzipping' + target_build + '\n\n----------')
    zip_ref.extractall(target)
    print('file has been extracted\n\n---------')
    zip_ref.close()
    send2trash.send2trash(target_build)
    print(target_build + ' has been sent to trash')


latest_file = getLatestBuild(source, target)
target_build = change_dir(latest_file)
extractZip(target_build)

【问题讨论】:

  • 如何运行脚本?
  • 嗨,我从终端和 IDLE 都试过了
  • 解压文件后得到了什么?解压后的扩展名是什么?

标签: python macos desktop-application zipfile


【解决方案1】:

似乎问题归结为符号链接被破坏。

普通提取物

-rw-r--r--  1 daniel  staff    29B 22 Aug 17:36 QtConcurrent
-rw-r--r--  1 daniel  staff    26B 22 Aug 17:36 Resources
drwxr-xr-x  4 daniel  staff   136B 22 Aug 17:36 Versions

Python 提取

lrwxr-xr-x  1 daniel  staff    29B 22 Aug 17:37 QtConcurrent -> Versions/Current/QtConcurrent
lrwxr-xr-x  1 daniel  staff    26B 22 Aug 17:37 Resources -> Versions/Current/Resources
drwxr-xr-x  4 daniel  staff   136B 22 Aug 17:37 Versions

使用标准 OSX 工具提取时按预期工作

    os.system("unzip -q -o %s -d %s" % (target_build, target))

【讨论】:

    猜你喜欢
    • 2018-09-11
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2017-11-16
    • 2015-02-24
    相关资源
    最近更新 更多