gpt4 book ai didi

python - 从 PyPI 安装我的 sdist 将文件放在意想不到的地方

转载 作者:太空狗 更新时间:2023-10-29 21:53:40 24 4
gpt4 key购买 nike

我的问题是,当我将我的 Python 包上传到 PyPI,然后使用 pip 从那里安装它时,我的应用程序崩溃了,因为它将我的文件安装到与我从本地 sdist 安装完全相同的包时完全不同的位置.

从本地 sdist 安装会像这样在我的系统上放置文件:

/Python27/
Lib/
site-packages/
gloopy-0.1.alpha-py2.7.egg/ (egg and install info files)
data/ (images and shader source)
doc/ (html)
examples/ (.py scripts that use the library)
gloopy/ (source)

这符合我的预期,并且工作正常(例如,我的源可以找到我的数据目录,因为它们彼此相邻,就像它们在开发中一样。)

如果我将相同的 sdist 上传到 PyPI,然后使用 pip 从那里安装它,那么事情看起来就会大不相同:

/Python27/
data/ (images and shader source)
doc/ (html)
Lib/
site-packages/
gloopy-0.1.alpha-py2.7.egg/ (egg and install info files)
gloopy/ (source files)
examples/ (.py scripts that use the library)

这根本行不通 - 我的应用找不到它的数据文件,而且显然它一团糟,用我所有的垃圾污染了顶级/python27 目录。

我做错了什么?如何使 pip 安装的行为类似于本地 sdist 安装?这甚至是我应该努力实现的目标吗?

详情

我已经安装了 setuptools,并且还分发了,我正在调用 distribute_setup.use_setuptools()

WindowsXP, Python2.7.

我的开发目录是这样的:

/gloopy
/data (image files and GLSL shader souce read at runtime)
/doc (html files)
/examples (some scripts to show off the library)
/gloopy (the library itself)

我的 MANIFEST.in 提到了我想包含在 sdist 中的所有文件,包括数据、示例和文档目录中的所有内容:

recursive-include data *.*
recursive-include examples *.py
recursive-include doc/html *.html *.css *.js *.png
include LICENSE.txt
include TODO.txt

我的 setup.py 非常冗长,但我想最好是将它包含在这里,对吧?我还包括对 MANIFEST.in 中提到的相同数据/文档/示例目录的重复引用,因为我知道这是为了在安装期间将这些文件从 sdist 复制到系统所必需的。

NAME = 'gloopy'
VERSION= __import__(NAME).VERSION
RELEASE = __import__(NAME).RELEASE
SCRIPT = None
CONSOLE = False

def main():
import sys
from pprint import pprint

from setup_utils import distribute_setup
from setup_utils.sdist_setup import get_sdist_config
distribute_setup.use_setuptools()
from setuptools import setup

description, long_description = read_description()
config = dict(
name=name,
version=version,
description=description,
long_description=long_description,
keywords='',
packages=find_packages(),
data_files=[
('examples', glob('examples/*.py')),
('data/shaders', glob('data/shaders/*.*')),
('doc', glob('doc/html/*.*')),
('doc/_images', glob('doc/html/_images/*.*')),
('doc/_modules', glob('doc/html/_modules/*.*')),
('doc/_modules/gloopy', glob('doc/html/_modules/gloopy/*.*')),
('doc/_modules/gloopy/geom', glob('doc/html/_modules/gloopy/geom/*.*')),
('doc/_modules/gloopy/move', glob('doc/html/_modules/gloopy/move/*.*')),
('doc/_modules/gloopy/shapes', glob('doc/html/_modules/gloopy/shapes/*.*')),
('doc/_modules/gloopy/util', glob('doc/html/_modules/gloopy/util/*.*')),
('doc/_modules/gloopy/view', glob('doc/html/_modules/gloopy/view/*.*')),
('doc/_static', glob('doc/html/_static/*.*')),
('doc/_api', glob('doc/html/_api/*.*')),
],
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 2.7',
],
# see classifiers http://pypi.python.org/pypi?:action=list_classifiers
)

config.update(dict(
author='Jonathan Hartley',
author_email='tartley@tartley.com',
url='http://bitbucket.org/tartley/gloopy',
license='New BSD',
) )

if '--verbose' in sys.argv:
pprint(config)

setup(**config)


if __name__ == '__main__':
main()

最佳答案

data_files 参数用于不属于包的数据文件。您可能应该改用 package_data

参见 https://docs.python.org/3/distutils/setupscript.html#installing-package-data

那不会将数据安装在站点包/数据中,但在我看来,无论如何都不应该安装它。您不会知道它属于哪个包。它应该安装在 site-packages//gloopy-0.1.alpha-py2.7.egg/[data|doc|examples] IMO 中。

如果你真的认为数据不是包数据,那么你应该使用 data_files 并且在这种情况下 pip 会正确安装它,而我会声称 setup.py install 将其安装在错误的位置。但在我看来,在这种情况下,它是 package_data,因为它与包相关,不被其他软件使用。

关于python - 从 PyPI 安装我的 sdist 将文件放在意想不到的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5192386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com