使用 PyPi 版本打包大型文件集的最佳方法是什么?

What is the best way to package large filesets with a PyPi release?

我目前正在开发一个 PyPi 包,该包使用约 350 MB 的音频文件和 Tkinter GUI。由于 50 MB 的限制,我无法将这些音频文件上传到 PyPi,因此我采用了一种创造性的方法来获取最终用户安装的文件。

我创建了一个函数 audio_download(),它使用 GitPython 执行以下代码:

import os
from git import Repo
def audio_download():
    path = os.path.join(os.path.split(os.path.realpath(__file__))[0],'audio')
    git_link = GIT_LINK_HERE
    if not os.path.isdir(path):
        print('Cloning audio files to the package directory...')
        Repo.clone_from(git_link,path)
        print('Audio engine downloaded to {}'.format(path))
    else:
        print('Audio files already present in {}. If you want to uninstall, you must manually delete the folder.'.format(path))

简而言之,它会检查音频文件文件夹的包目录,如果不存在,它会克隆包含这些文件的 GitHub 存储库。

三个问题:

  1. 以这种方式操作使用 pip 安装的包是否安全?
  2. 是否有更好的方法可以在所有平台上仅使用 Python 执行此操作? GitPython 需要安装 git,我希望即使是最没有经验的 Python 用户也能尽可能轻松地进行安装。
  3. 如果我想让用户将文件下载到他们选择的文件夹(而不是一些深层嵌套的 Python 包),那么在我的 PyPi 包中跟踪文件夹的最佳方法是什么?简单地写一个带有文件夹路径的文件,或者更优雅的东西?

您可以使用 package_data (assuming you're using setuptools). But it's not really ideal to have such big files, probably you'd have to sort this out with PyPI. It's probably better to ask the user (via a GUI dialog for example) to trigger the download after the first start of the application and store those in the user's application directory 将大型音频文件放入发行版中(或者让用户再次通过 GUI 对话框选择目标目录)。