从PyPI安装我的sdist会将文件放在意想不到的地方 [英] Installing my sdist from PyPI puts the files in unexpected places

查看:81
本文介绍了从PyPI安装我的sdist会将文件放在意想不到的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My problem is that when I upload my Python package to PyPI, and then install it from there using pip, my app breaks because it installs my files into completely different locations than when I simply install the exact same package from a local sdist.

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

Installing from the local sdist puts files on my system like this:

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

这与我期望的一样,并且运行良好(例如,我的源代码可以找到我的数据目录,因为它们彼此相邻,就像在开发中一样).

This is much as I'd expect, and works fine (e.g. my source can find my data dir, because they lie next to each other, just like they do in development.)

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

If I upload the same sdist to PyPI and then install it from there, using pip, then things look very different:

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

This doesn't work at all - my app can't find its data files, plus obviously it's a mess, polluting the top-level /python27 directory with all my junk.

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

What am I doing wrong? How do I make the pip install behave like the local sdist install? Is that even what I should be trying to achieve?

我已经安装了setuptools,并且也进行了分发,并且我正在调用Distribution_setup.use_setuptools()

I have setuptools installed, and also distribute, and I'm calling distribute_setup.use_setuptools()

WindowsXP,Python2.7.

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中的所有文件,包括数据,示例和doc目录中的所有内容:

My MANIFEST.in mentions all the files I want to be included in the sdist, including everything in the data, examples and doc directories:

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中提到的相同data/doc/examples目录的重复引用,因为我知道这是必需的,以便在安装过程中将这些文件从sdist复制到系统中.

My setup.py is quite verbose, but I guess the best thing is to include it here, right? I also includes duplicate references to the same data / doc / examples directories as are mentioned in the MANIFEST.in, because I understand this is required in order for these files to be copied from the sdist to the system during install.

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.

The data_files parameter is for data files who isn't a part of the package. You should probably use package_data instead.

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

那不会在site-packages/data中安装数据,但是我认为那不是应该安装的位置.您将不知道它属于哪个软件包.它应该安装在site-packages//gloopy-0.1.alpha-py2.7.egg/[data|doc|examples] IMO中.

That wouldn't install the data in site-packages/data, but in my opinion that's not where is should be installed anyway. You won't know which package it's a part of. It should be installed in site-packages//gloopy-0.1.alpha-py2.7.egg/[data|doc|examples] IMO.

如果您确实认为数据不是打包数据,则应使用data_files,在这种情况下,pip可以正确安装它,而我声称setup.py install会将其安装在错误的位置.但在我看来,在这种情况下,它是package_data,因为它与软件包有关,而未被其他软件使用.

If you really do think the data is not package data, then you should use data_files and in that case pip installs it correctly, while I'd claim setup.py install installs it in the wrong place. But in my opinion, in this case, it is package_data, as it's related to the package, and not used by other software.

这篇关于从PyPI安装我的sdist会将文件放在意想不到的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆