1. <small id='EvFh5'></small><noframes id='EvFh5'>

      1. <legend id='EvFh5'><style id='EvFh5'><dir id='EvFh5'><q id='EvFh5'></q></dir></style></legend>

        <tfoot id='EvFh5'></tfoot>

          <bdo id='EvFh5'></bdo><ul id='EvFh5'></ul>

      2. <i id='EvFh5'><tr id='EvFh5'><dt id='EvFh5'><q id='EvFh5'><span id='EvFh5'><b id='EvFh5'><form id='EvFh5'><ins id='EvFh5'></ins><ul id='EvFh5'></ul><sub id='EvFh5'></sub></form><legend id='EvFh5'></legend><bdo id='EvFh5'><pre id='EvFh5'><center id='EvFh5'></center></pre></bdo></b><th id='EvFh5'></th></span></q></dt></tr></i><div id='EvFh5'><tfoot id='EvFh5'></tfoot><dl id='EvFh5'><fieldset id='EvFh5'></fieldset></dl></div>

        如何将静态文件包含到 setuptools - python 包

        时间:2023-09-14
          <tfoot id='JqhDF'></tfoot>
          <i id='JqhDF'><tr id='JqhDF'><dt id='JqhDF'><q id='JqhDF'><span id='JqhDF'><b id='JqhDF'><form id='JqhDF'><ins id='JqhDF'></ins><ul id='JqhDF'></ul><sub id='JqhDF'></sub></form><legend id='JqhDF'></legend><bdo id='JqhDF'><pre id='JqhDF'><center id='JqhDF'></center></pre></bdo></b><th id='JqhDF'></th></span></q></dt></tr></i><div id='JqhDF'><tfoot id='JqhDF'></tfoot><dl id='JqhDF'><fieldset id='JqhDF'></fieldset></dl></div>
          <legend id='JqhDF'><style id='JqhDF'><dir id='JqhDF'><q id='JqhDF'></q></dir></style></legend>
              <tbody id='JqhDF'></tbody>

                  <bdo id='JqhDF'></bdo><ul id='JqhDF'></ul>

                  <small id='JqhDF'></small><noframes id='JqhDF'>

                  本文介绍了如何将静态文件包含到 setuptools - python 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想将 ./static/data.txt 包含到 setuptools,这是我的代码:

                  I want to include the ./static/data.txt to setuptools, here is my code:

                  # setup.py
                  import os,glob
                  from setuptools import setup,find_packages
                  
                  setup(
                      name = "PotatoProject",
                      version = "0.1.1",
                      author = "Master Splinter",
                      author_email = "splinter@initech.com",
                      description = ("The potatoproject!"),
                      url = 'http://www.google.com',
                      license = "BSD",
                  
                      # adding packages
                      packages=find_packages('src'),
                      package_dir = {'':'src'},
                  
                      # trying to add files...
                      include_package_data = True,
                      package_data = {
                          '': ['*.txt'],
                          '': ['static/*.txt'],
                          'static': ['*.txt'],
                      },
                  
                      scripts=['src/startPotato'],
                      classifiers=[
                          "Development Status :: 3 - Alpha",
                          "Topic :: Utilities",
                          "License :: OSI Approved :: BSD License",
                      ],
                  )
                  

                  文件系统:

                  .
                  ├── setup.py
                  └── src
                      ├── distutils_setup.py
                      ├── Potato
                      │   ├── __init__.py
                      │   ├── potatoData.txt
                      │   └── printer.py
                      ├── startPotato
                      ├── static
                      │   └── data.txt
                      └── Tomato
                          ├── big.py
                          └── __init__.py
                  

                  运行时的输出:python setup.py sdist

                  running sdist
                  running egg_info
                  creating src/PotatoProject.egg-info
                  writing src/PotatoProject.egg-info/PKG-INFO
                  writing top-level names to src/PotatoProject.egg-info/top_level.txt
                  writing dependency_links to src/PotatoProject.egg-info/dependency_links.txt
                  writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
                  reading manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
                  writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
                  warning: sdist: standard file not found: should have one of README, README.txt
                  
                  creating PotatoProject-0.1.1
                  creating PotatoProject-0.1.1/src
                  creating PotatoProject-0.1.1/src/Potato
                  creating PotatoProject-0.1.1/src/PotatoProject.egg-info
                  creating PotatoProject-0.1.1/src/Tomato
                  making hard links in PotatoProject-0.1.1...
                  hard linking setup.py -> PotatoProject-0.1.1
                  hard linking src/startPotato -> PotatoProject-0.1.1/src
                  hard linking src/Potato/__init__.py -> PotatoProject-0.1.1/src/Potato
                  hard linking src/Potato/printer.py -> PotatoProject-0.1.1/src/Potato
                  hard linking src/PotatoProject.egg-info/PKG-INFO -> PotatoProject-0.1.1/src/PotatoProject.egg-info
                  hard linking src/PotatoProject.egg-info/SOURCES.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
                  hard linking src/PotatoProject.egg-info/dependency_links.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
                  hard linking src/PotatoProject.egg-info/top_level.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
                  hard linking src/Tomato/__init__.py -> PotatoProject-0.1.1/src/Tomato
                  hard linking src/Tomato/big.py -> PotatoProject-0.1.1/src/Tomato
                  Writing PotatoProject-0.1.1/setup.cfg
                  creating dist
                  Creating tar archive
                  removing 'PotatoProject-0.1.1' (and everything under it)
                  

                  并且没有添加 txt!没有 static/data.txt 也没有 Potato/potatoData.txt...

                  and no txt added! No static/data.txt nor Potato/potatoData.txt...

                  我错过了什么?!

                  推荐答案

                  正如评论中指出的,添加静态文件有两种方法:

                  As pointed out in the comments, there are 2 ways to add the static files:

                  setup.py 目录下的 MANIFEST.in 文件如下所示:

                  A MANIFEST.in file in the same directory of setup.py that looks like this:

                  include src/static/*
                  include src/Potato/*.txt
                  

                  setup.py 中使用 include_package_data = True.

                  package_data = {
                      'static': ['*'],
                      'Potato': ['*.txt']
                  }
                  

                  指定setup.py中的文件.

                  include_package_data 将使 package_data 信息无效.

                  官方文档:
                  https://setuptools.readthedocs.io/en/latest/userguide/datafiles.html

                  这篇关于如何将静态文件包含到 setuptools - python 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:列出作为 python 包一部分的所有模块? 下一篇:将版本嵌入 Python 包的标准方法?

                  相关文章

                  最新文章

                • <small id='kmtQv'></small><noframes id='kmtQv'>

                    <bdo id='kmtQv'></bdo><ul id='kmtQv'></ul>
                    <tfoot id='kmtQv'></tfoot>

                    <legend id='kmtQv'><style id='kmtQv'><dir id='kmtQv'><q id='kmtQv'></q></dir></style></legend>

                      <i id='kmtQv'><tr id='kmtQv'><dt id='kmtQv'><q id='kmtQv'><span id='kmtQv'><b id='kmtQv'><form id='kmtQv'><ins id='kmtQv'></ins><ul id='kmtQv'></ul><sub id='kmtQv'></sub></form><legend id='kmtQv'></legend><bdo id='kmtQv'><pre id='kmtQv'><center id='kmtQv'></center></pre></bdo></b><th id='kmtQv'></th></span></q></dt></tr></i><div id='kmtQv'><tfoot id='kmtQv'></tfoot><dl id='kmtQv'><fieldset id='kmtQv'></fieldset></dl></div>