简体   繁体   English

Setup.py 没有安装我的 package_data

[英]Setup.py is not installing my package_data

On both Ubuntu 16.04 and Windows 7 (pip 18.1, python 2.7.15) , I am encountering an issue where I have package data that makes its way into the tar.gz file, but they do not get installed to my scripts directory when I install with pip.在 Ubuntu 16.04 和 Windows 7 (pip 18.1, python 2.7.15) 上,我遇到了一个问题,我的package data进入了 tar.gz 文件,但是当我将它们安装到我的脚本目录时用pip安装。 My scripts directory on windows is \\Python27\\Scripts .我在 Windows 上的脚本目录是\\Python27\\Scripts I also checked in site-packages and the file doesn't show up there.我还签入了site-packages ,但该文件没有显示在那里。 I want to have a textfile appear alongside the python scripts when installed via pip, and I think that using data_files does not achieve this (according to setup.py not installing data files ?通过 pip 安装时,我希望在 python 脚本旁边显示一个文本文件,我认为使用data_files无法实现这一点(根据setup.py 未安装数据文件

My package structure has all files ( hello.py, MANIFEST.IN, setup.py )in the one root folder called fakeapp .我的包结构在一个名为fakeapp根文件夹中包含所有文件( hello.py, MANIFEST.IN, setup.py )。 I would like to keep this structure as the project that I actually am trying to fix has this structure.我想保留这种结构,因为我实际尝试修复的项目具有这种结构。

I have looked up many answers and tried:我查了很多答案并尝试过:

  • adding an empty __init__.py to the root of the repo and this didn't fix it.将一个空的__init__.py添加到 repo 的根目录,但这并没有解决它。
  • I've tried adding and removing include_package_files=True to no avail我试过添加和删除include_package_files=True无济于事
  • I've tried specifying package_data={'':['texto.txt']} as well as我试过指定package_data={'':['texto.txt']}以及
    adding include texto.txt to MANIFEST.in to no avail.include texto.txt添加到MANIFEST.in无济于事。
  • This answer : suggests to use bdist, which also didn't work. 这个答案:建议使用 bdist,这也不起作用。

I'm sure that this is a duplicate question but I have not been able to get any solution to work.我确定这是一个重复的问题,但我无法找到任何解决方案。

So here's my test case: setup.py所以这是我的测试用例:setup.py

from setuptools import setup
setup(
    author='hi',
    author_email='hi@hi.com',
    description="test",
    scripts=['hello.py',],
    license='MIT',
    name='hi',
    version='v2018.12.02',
    include_package_data=True
)

hello.py:你好.py:

#!/usr/bin/env python

def main():
    print('hello world!')

if __name__ == '__main__':
    main()

MANIFEST.in:清单.in:

include texto.txt

I created a tar.gz in dist/ with我在 dist/ 中创建了一个 tar.gz

python setup.py sdist

and my texto.txt is in that tarball.而我的 texto.txt 就在那个 tarball 中。

and then i installed with然后我安装了

pip install dist\hi-2018.12.2.tar.gz

and only hello.py makes its way into C:\\Python2.7\\Scripts只有hello.py进入C:\\Python2.7\\Scripts

What am I doing wrong?我究竟做错了什么?

Directory tree :目录树:

│   hello.py
│   MANIFEST.in
│   setup.py
│   texto.txt
│
├───dist
│       hi-2018.12.2.tar.gz
│
└───hi.egg-info
        dependency_links.txt
        PKG-INFO
        SOURCES.txt
        top_level.txt

texto.txt is not actually package data, as it is not inside a package (a directory with an __init__.py ), and thus it will not be installed. texto.txt实际上不是包数据,因为它不在包内(带有__init__.py的目录),因此不会被安装。 The simplest way to get what you want is to restructure your code so that it installs a package hello instead of a flat module hello.py , with hello.py being moved to hello/__init__.py and texto.txt being moved to hello/texto.txt .获得所需内容的最简单方法是重构代码,使其安装包hello而不是平面模块hello.py ,将hello.py移至hello/__init__.py并将texto.txt移至hello/texto.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM