Setup.py 没有安装我的 package_data
Setup.py is not installing my package_data
在 Ubuntu 16.04 和 Windows 7 (pip 18.1, python 2.7.15) 上,我遇到了 package data
的问题进入 tar.gz 文件,但当我使用 pip 安装时,它们没有安装到我的脚本目录中。我在 windows 上的脚本目录是 \Python27\Scripts
。我还检查了 site-packages
,但该文件没有显示在那里。当通过 pip 安装时,我希望在 python 脚本旁边显示一个文本文件,我认为使用 data_files
无法实现这一点(根据
setup.py not installing data files ?
我的包结构包含一个名为 fakeapp
的根文件夹中的所有文件 (hello.py, MANIFEST.IN, setup.py
)。我想保留此结构,因为我实际尝试修复的项目具有此结构。
我查阅了很多答案并尝试过:
- 向存储库的根目录添加一个空的
__init__.py
,但这并没有解决问题。
- 我尝试添加和删除
include_package_files=True
无济于事
- 我试过指定
package_data={'':['texto.txt']}
以及
将 include texto.txt
添加到 MANIFEST.in
无济于事。
- This answer:建议使用bdist,也没有用。
我确定这是一个重复的问题,但我无法找到任何解决方案。
所以这是我的测试用例:
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:
#!/usr/bin/env python
def main():
print('hello world!')
if __name__ == '__main__':
main()
MANIFEST.in:
include texto.txt
我在 dist/ 中用
创建了一个 tar.gz
python setup.py sdist
我的 texto.txt 在那个压缩包里。
然后我安装了
pip install dist\hi-2018.12.2.tar.gz
并且只有 hello.py
进入 C:\Python2.7\Scripts
我做错了什么?
目录树:
│ 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
实际上不是包数据,因为它不在包内(带有 __init__.py
的目录),因此不会安装。获得你想要的东西的最简单方法是重组你的代码,以便它安装一个包 hello
而不是一个平面模块 hello.py
,hello.py
被移动到 hello/__init__.py
并且texto.txt
正在移至 hello/texto.txt
。
在 Ubuntu 16.04 和 Windows 7 (pip 18.1, python 2.7.15) 上,我遇到了 package data
的问题进入 tar.gz 文件,但当我使用 pip 安装时,它们没有安装到我的脚本目录中。我在 windows 上的脚本目录是 \Python27\Scripts
。我还检查了 site-packages
,但该文件没有显示在那里。当通过 pip 安装时,我希望在 python 脚本旁边显示一个文本文件,我认为使用 data_files
无法实现这一点(根据
setup.py not installing data files ?
我的包结构包含一个名为 fakeapp
的根文件夹中的所有文件 (hello.py, MANIFEST.IN, setup.py
)。我想保留此结构,因为我实际尝试修复的项目具有此结构。
我查阅了很多答案并尝试过:
- 向存储库的根目录添加一个空的
__init__.py
,但这并没有解决问题。 - 我尝试添加和删除
include_package_files=True
无济于事 - 我试过指定
package_data={'':['texto.txt']}
以及
将include texto.txt
添加到MANIFEST.in
无济于事。 - This answer:建议使用bdist,也没有用。
我确定这是一个重复的问题,但我无法找到任何解决方案。
所以这是我的测试用例: 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:
#!/usr/bin/env python
def main():
print('hello world!')
if __name__ == '__main__':
main()
MANIFEST.in:
include texto.txt
我在 dist/ 中用
创建了一个 tar.gzpython setup.py sdist
我的 texto.txt 在那个压缩包里。
然后我安装了
pip install dist\hi-2018.12.2.tar.gz
并且只有 hello.py
进入 C:\Python2.7\Scripts
我做错了什么?
目录树:
│ 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
实际上不是包数据,因为它不在包内(带有 __init__.py
的目录),因此不会安装。获得你想要的东西的最简单方法是重组你的代码,以便它安装一个包 hello
而不是一个平面模块 hello.py
,hello.py
被移动到 hello/__init__.py
并且texto.txt
正在移至 hello/texto.txt
。