Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从PyPI安装my sdist会将文件放在意外的位置_Python_Setuptools_Distutils_Distribute_Pypi - Fatal编程技术网

Python 从PyPI安装my sdist会将文件放在意外的位置

Python 从PyPI安装my sdist会将文件放在意外的位置,python,setuptools,distutils,distribute,pypi,Python,Setuptools,Distutils,Distribute,Pypi,我的问题是,当我将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 sour

我的问题是,当我将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)
/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)
这正是我所期望的,并且运行良好(例如,我的源代码可以找到我的数据目录,因为它们彼此相邻,就像在开发中一样)

如果我将同一个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,我正在调用distribute\u setup.use\u setuptools()

WindowsXP,Python2.7

我的开发目录如下所示:

/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)
/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)
My 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中提到的相同data/doc/examples目录的重复引用,因为我知道这是在安装期间将这些文件从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\u files
用于不属于包的数据文件。您可能应该使用
package\u数据

这不会在站点包/数据中安装数据,但在我看来,无论如何都不应该在那里安装。你不知道它是哪个包的一部分。它应该安装在
站点包//gloopy-0.1.alpha-py2.7.egg/[data | doc | examples]
IMO中


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

嘿,这里。太棒了-谢谢你的回答。回顾这些链接,我认为您没有明确提到的一个重要要点是,我应该始终在setup.py中使用“package_data”,而不是“data_files”。因此,是否一致认为永远不应使用“数据文件”?这让我感到困惑,因为它与我对如何在Python项目中布局目录的理解相矛盾,因为它意味着“数据”目录在包源目录中,而不是在它旁边。我完全同意您的观点,数据| doc |示例应该安装在站点包/gloopy-0.1.alpha-py2.7.egg中。你暗示“数据文件”只能由其他软件使用的数据使用,这对我很有启发。谢谢。哎呀,您的回答提醒我,我为本地sdist安装绘制的目录布局错误。”数据“etc”并没有进入站点包,而是进入站点包/gloopy-0.1.alpha-py2.7.egg,正如您所建议的那样。现在修好了。@Tartley:啊。好。我真想知道为什么会有不同。我们真的需要在Python中直接了解安装过程。(希望distutils2能做到这一点)。你的主链接已经死了。