【问题标题】:Best way to include a big file that can't be stored on GitHub in a python package将无法存储在 GitHub 上的大文件包含在 python 包中的最佳方法
【发布时间】:2018-10-23 13:00:45
【问题描述】:

当我制作一个python包时,我经常会包含一些非python文件,例如requirements.txt、配置文件、文档或小数据文件。使用以下脚本,任何用户都可以轻松地直接从 github 上 pip 安装包:

from setuptools import setup, find_packages
import os 
current_folder = os.path.dirname(os.path.abspath(__file__))
version = '0.0.0.0.0.0' # year.month.day.hour.minute.second
with open(os.path.join(current_folder,'VERSION')) as version_file:
    version = version_file.read().strip()

setup(name='package_name',
      version=version,
      description='My Little Python Package',
      url='https://github.com/github_user_name/package_name',
      author='Me',
      author_email='me@email.com',
      license='MIT',
      include_package_data=True,
      packages=find_packages(exclude=['docs', 'tests']),
      package_data={'': ['package_name/resources/*', 'package_name/conf.yml']},
      install_requires=[
          'numpy',
          'scipy',
          'PyMySQL',
          'PyYAML'
      ],
      zip_safe=False)

然后,如果我这样做:pip install git+https://github.com/github_user_name/package_name,该软件包将安装必要的文件。遗憾的是,无法在 GitHub 上上传超过 50 Mb 的文件。假设我想在包中提供一个 1 Gb 的文件(例如:100 万个小文本的数据集)。这样做的最佳做法是什么?一些建议:

  1. 在 GitHub 的自述文件上提供一个附加链接作为先决条件。
  2. 在 setup.py 文件中添加一行下载数据(理想情况下它将数据存储在包目录中,不确定是否可行)。
  3. 在获取数据的包中创建一个显式脚本。
  4. 其他?

我知道的唯一例子是nltk,它使用了第三个选项。

【问题讨论】:

    标签: python file download package


    【解决方案1】:

    您应该查看Git Large file storage。它将创建指向另一台服务器的大文件的指针,因此您可以超过 50 MB 的大小限制。

    来自他们的入门指南:

    # This part is only done once
    git lfs install
    git lfs track "*.psd" # Or your file extension
    git add .gitattributes
    
    # Normal workflow begins
    git add file.psd
    git commit -m "Add design file"
    git push origin master
    

    【讨论】:

    • 太好了,我没有意识到它专门与 GitHub 合作。我仍然想找到一种pythonic方式来做到这一点:-)
    猜你喜欢
    • 2011-07-20
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2012-10-18
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多