MANIFEST.in 在“python setup.py install”上被忽略——没有安装数据文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3596979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:53:48  来源:igfitidea点击:

MANIFEST.in ignored on "python setup.py install" - no data files installed?

pythonbuildinstalldistutils

提问by Steven Sproat

Here's my stripped-down setup.py script with non-code stuff removed:

这是我删除了非代码内容的精简 setup.py 脚本:

#!/usr/bin/env python

from distutils.core import setup
from whyteboard.misc import meta


setup(
    name = 'Whyteboard',
    version = meta.version,

    packages = ['whyteboard', 'whyteboard.gui', 'whyteboard.lib', 'whyteboard.lib.pubsub',
                'whyteboard.lib.pubsub.core', 'whyteboard.lib.pubsub.utils', 'whyteboard.misc'],

    py_modules = ['whyteboard'],
    scripts = ['whyteboard.py'],
)

MANIFEST.in:

清单.in:

include *.txt
include whyteboard-help/*.*
recursive-include locale *.mo
recursive-include images *.png

When I run "python setup.py install sdist" I get a nice .tar.gz with a "whyteboard-0.41" root folder, with my locale/ images/ and whyteboard-help/ folders inside. This also has my whyteboard.py script that launches my program from inside the whyteboard source package.

当我运行“python setup.py install sdist”时,我得到了一个不错的 .tar.gz 文件,里面有一个“whyteboard-0.41”根文件夹,里面有我的 locale/images/ 和 whyteboard-help/ 文件夹。这也有我的whyteboard.py 脚本,它从whyteboard 源包中启动我的程序。

So:

所以:

whyteboard/
 ├── locale/
 ├── images
 ├── whyteboard-help/
 ├── whyteboard/
 │  ├── __init__.py
 │  └── other packages etc
 ├── whyteboard.py
 ├── README
 ├── setup.py
 └── CHANGELOG

This mirrors the source of my program, is how everything should be, and is correct.

这反映了我的程序的来源,一切都应该是这样,并且是正确的。

However when I run "python setup.py install" none of my data files are written - only the "whyteboard" source package, and the whyteboard.py is placed in /usr/local/lib/python2.6/dist-packages/.

然而,当我运行“python setup.py install”时,我的数据文件都没有被写入——只有“whyteboard”源包,而whyteboard.py被放置在/usr/local/lib/python2.6/dist-packages/ .

Ideally, I'd like the same directory structure as what's been generated in the .tar.gz file to be created in dist-packages, as this is how my program expects to look for its resources.

理想情况下,我希望在 dist-packages 中创建与在 .tar.gz 文件中生成的目录结构相同的目录结构,因为这是我的程序期望查找其资源的方式。

How can I get "install" to create this directory structure? It seems to be ignoring my manifest file, as far as I can tell.

如何获得“安装”以创建此目录结构?据我所知,它似乎忽略了我的清单文件。

采纳答案by Carl Meyer

Some notes in addition to Ned's answer (which hits on the core problem):

除了 Ned 的回答(触及核心问题)之外,还有一些说明:

Distutils does not install Python packages and modules inside a per-project subdirectory within site-packages(or dist-packageson Debian/Ubuntu): they are installed directly into site-packages, as you've seen. So the containing whyteboard-xxdirectory in your sdist will not exist in the final installed form.

Distutils 不会在site-packages(或dist-packages在 Debian/Ubuntu 上)每个项目的子目录中安装 Python 包和模块:它们直接安装到 中site-packages,如您所见。因此,whyteboard-xx最终安装的形式中将不存在 sdist 中的包含目录。

One implication of this is that you should be careful to name your data_filesin a way that clarifies what project they belong to, because those files/directories are installed directly into the global site-packagesdirectory, not inside any containing whyteboarddirectory.

这样做的一个含义是,您应该小心地data_files以一种阐明它们属于哪个项目的方式命名您的文件,因为这些文件/目录直接安装到全局site-packages目录中,而不是任何包含whyteboard目录中。

Or you could instead make your data package_dataof the whyteboardpackage (which means it needs to live inside that package, i.e. next to __init__.py), and then this isn't a problem.

或者你可以反而让你的数据package_data中的whyteboard包(这意味着它需要生活里面那个包,即旁__init__.py),然后这不是一个问题。

Lastly, it doesn't make much sense to have both a whyteboard.pymodule in py_modulesand a whyteboard/__init__.pypackage in packages. The two are mutually exclusive, and if you have both, the whyteboard.pymodule will be ignored by imports in favor of the package of the same name.

最后,同时拥有一个whyteboard.py模块py_modules和一个whyteboard/__init__.py包并没有多大意义packages。两者是互斥的,如果两者都有,whyteboard.py模块将被导入忽略,而支持同名包。

If whyteboard.pyis just a script, and is not intended to be imported, then you should use the scriptsoption for it, and remove it from py_modules.

如果whyteboard.py只是一个脚本,并且不打算导入,那么您应该为它使用脚本选项,并将其从py_modules.

回答by Ned Deily

MANIFEST.intells Distutils what files to include in the source distribution but it does not directly affect what files are installed. For that you need to include the appropriate files in the setup.pyfile, generally either as package dataor as additional files.

MANIFEST.in告诉 Distutils 在源代码分发中包含哪些文件,但它不会直接影响安装哪些文件。为此,您需要在文件中包含适当的setup.py文件,通常作为包数据附加文件

回答by Scott Persinger

Running python 2.6.1 on Mac OSX, I had absolutely no luck except by using the data_filesparameter in setup.py. Everything with MANIFEST.in simply resulted in files being included in the dist package, but never installed. I checked some other packages and they were indeed using data_files to specify additional files.

在 Mac OSX 上运行 python 2.6.1,除了使用setup.py 中的data_files参数外,我绝对没有运气。MANIFEST.in 的所有内容只会导致文件包含在 dist 包中,但从未安装。我检查了一些其他包,他们确实使用 data_files 来指定其他文件。

I created a short function to help enumerate all the files from a directory tree in the

我创建了一个简短的函数来帮助枚举目录树中的所有文件

(target_dir, [file list])format that data_files expects:

(target_dir, [file list])data_files 期望的格式:

def gen_data_files(*dirs):
    results = []

    for src_dir in dirs:
        for root,dirs,files in os.walk(src_dir):
            results.append((root, map(lambda f:root + "/" + f, files)))
    return results

Now I can just call this inside my setup call:

现在我可以在我的设置调用中调用它:

setup(... data_files = gen_data_files("docs", "lib") ...

And everything in those trees gets installed.

那些树中的所有东西都被安装了。

回答by Juho Rutila

You should use setuptools:

您应该使用设置工具:

#!/usr/bin/env python

from setuptools import setup, find_packages
from whyteboard.misc import meta


setup(
  name = 'Whyteboard',
  version = meta.version,

  packages = find_packages(),
  include_package_data=True,

  py_modules = ['whyteboard'],
  scripts = ['whyteboard.py'],
)

This is not actually using the MANIFEST file to do the job, but it includes all the needed files.

这实际上并没有使用 MANIFEST 文件来完成这项工作,但它包含了所有需要的文件。

回答by Greg

I couldn't figure out why my MANIFEST.infile was being ignored when I ran python setup.py install- turns out include_package_data=Truesolves the problem. The package_dataoption isn't actually required.

我不知道为什么我的MANIFEST.in文件在运行时被忽略python setup.py install- 结果include_package_data=True解决了这个问题。该package_data选项实际上不是必需的。