无法打开应用程序“”。在pythonmacos中使用zipfile提取后

2024-04-25 19:35:35 发布

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

我无法在使用python从服务器提取构建然后提取之后启动应用程序。我收到错误消息“The application”“cannot be open”Iv在内容中的可执行文件上尝试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)

Tags: pathbuildref应用程序sourcetargetosdef
1条回答
网友
1楼 · 发布于 2024-04-25 19:35:35

似乎问题是由于符号链接被破坏。你知道吗

正常提取物

-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))

相关问题 更多 >