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

发布于 2024-09-17 07:39:14 字数 1328 浏览 12 评论 0 原文

这是我的精简 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:

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

当我运行“python setup.py install sdist”时,我得到一个不错的 .tar.gz ,其中包含“whyteboard-0.41”根文件夹,其中我的 locale/ images/ 和 Whyteboard-help/ 文件夹位于其中。这还有我的 Whyteboard.py 脚本,它从 Whyteboard 源代码包内启动我的程序。

所以:

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

这反映了我的程序的源代码,一切都应该如此,并且是正确的。

但是,当我运行“python setup.py install”时,没有写入任何数据文件 - 只有“whyteboard”源包,并且whyteboard.py放置在/usr/local/lib/python2.6/dist-packages/中。

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

我怎样才能“安装”来创建这个目录结构?据我所知,它似乎忽略了我的清单文件。

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

#!/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:

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.

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/.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

从此见与不见 2024-09-24 07:39:14

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

MANIFEST.in tells 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.py file, generally either as package data or as additional files.

我不吻晚风 2024-09-24 07:39:14

我不明白为什么当我运行 python setup.py install 时我的 MANIFEST.in 文件被忽略 - 结果是 include_package_data=True解决了问题。实际上并不需要 package_data 选项。

I couldn't figure out why my MANIFEST.in file was being ignored when I ran python setup.py install - turns out include_package_data=True solves the problem. The package_data option isn't actually required.

掌心的温暖 2024-09-24 07:39:14

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

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

这意味着您应该小心地命名您的data_files,以明确它们属于哪个项目,因为这些文件/目录直接安装到全局site-packages< /code> 目录,不在任何包含 whyteboard 目录内。

或者您可以将数据放在 whyteboard 包的 package_data 中(这意味着它需要位于该包内,即位于 __init__.py 旁边) ),然后这就不是问题了。

最后,在 py_modules 中同时拥有 whyteboard.py 模块和 whyteboard/__init__.py 包在 py_modules 中并没有多大意义。代码>包。两者是互斥的,如果两者都有,导入时将忽略 whyteboard.py 模块,转而使用同名的包。

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

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

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

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

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

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

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

゛时过境迁 2024-09-24 07:39:14

您应该使用 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'],
)

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

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.

萌吟 2024-09-24 07:39:14

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

目录树中的所有文件

我创建了一个简短的函数来帮助枚举data_files 期望的 (target_dir, [file list]) 格式的

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

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

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

:在那些树上安装。

Running python 2.6.1 on Mac OSX, I had absolutely no luck except by using the data_files parameter 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.

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:

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.

感性 2024-09-24 07:39:14

最小已发布的可运行示例

关键要点:只有 MANIFEST.in 对我有用,package_data 没有。

在 Ubuntu 19.10、Python 3.7.5、wheel==0.32.3、setuptools==41.1.0、twine==3.1.1 上测试。

最终用户如何使用 https://pypi.org/project/python 中的包-sample-package-with-data/

python3 -m pip install --user python-sample-package-with-data
python-sample-package-with-data

预期输出:

hello data

维护者如何发布它:

# One time setup.
python3 -m pip install --user setuptools wheel twine

# Every time you want to publish.
python setup.py sdist bdist_wheel
twine upload dist/*
rm -rf build dist *.egg-info

实际文件:

设置中的 MANIFEST

# Or else pip install cannot find README.md on the setup.py under certain conditions.
include README.md

# This actually adds the data file.
include python_sample_package_with_data/mydata.txt

python-sample-package-with-data

#!/usr/bin/env python3

import python_sample_package_with_data

print(python_sample_package_with_data.get_data(), end='')

python_sample_package_with_data/__init__.py

try:
    import importlib.resources as importlib_resources
except ImportError:
    # In PY<3.7 fall-back to backported `importlib_resources`.
    import importlib_resources

def get_data():
    return importlib_resources.read_text(__name__, 'mydata.txt')

python_sample_package_with_data/mydata.txt

hello data

.。 py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md')) as f:
    long_description = f.read()

setup(
    name='python-sample-package-with-data',
    version='0.0.3',
    description='My short description',
    long_description=long_description,
    long_description_content_type='text/markdown',
    url='https://github.com/cirosantilli/python-sample-package-with-data',
    author='Ciro Santilli',
    author_email='[email protected]',
    packages=find_packages(),
    include_package_data=True,
    scripts=['python-sample-package-with-data'],
)

参考书目:

Minimal published runnable example

Key takeaway: only MANIFEST.in worked for me, package_data did not.

Tested on Ubuntu 19.10, Python 3.7.5, wheel==0.32.3, setuptools==41.1.0, twine==3.1.1.

How end users use the package from https://pypi.org/project/python-sample-package-with-data/:

python3 -m pip install --user python-sample-package-with-data
python-sample-package-with-data

Expected output:

hello data

How maintainers publish it:

# One time setup.
python3 -m pip install --user setuptools wheel twine

# Every time you want to publish.
python setup.py sdist bdist_wheel
twine upload dist/*
rm -rf build dist *.egg-info

The actual files:

MANIFEST.in

# Or else pip install cannot find README.md on the setup.py under certain conditions.
include README.md

# This actually adds the data file.
include python_sample_package_with_data/mydata.txt

python-sample-package-with-data

#!/usr/bin/env python3

import python_sample_package_with_data

print(python_sample_package_with_data.get_data(), end='')

python_sample_package_with_data/__init__.py

try:
    import importlib.resources as importlib_resources
except ImportError:
    # In PY<3.7 fall-back to backported `importlib_resources`.
    import importlib_resources

def get_data():
    return importlib_resources.read_text(__name__, 'mydata.txt')

python_sample_package_with_data/mydata.txt

hello data

setup.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md')) as f:
    long_description = f.read()

setup(
    name='python-sample-package-with-data',
    version='0.0.3',
    description='My short description',
    long_description=long_description,
    long_description_content_type='text/markdown',
    url='https://github.com/cirosantilli/python-sample-package-with-data',
    author='Ciro Santilli',
    author_email='[email protected]',
    packages=find_packages(),
    include_package_data=True,
    scripts=['python-sample-package-with-data'],
)

Bibliography:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文