MANIFEST.in 在“python setup.py install”上被忽略- 没有安装数据文件?
这是我的精简 setup.py 脚本,删除了非代码内容:
#!/usr/bin/env python
from distutils.core import setup
from whyteboard.misc import meta
setup(
name = 'Whyteboard',
version = meta.version,
packages = ['whyteboard', 'whyteboard.gui', 'whyteboard.lib', 'whyteboard.lib.pubsub',
'whyteboard.lib.pubsub.core', 'whyteboard.lib.pubsub.utils', 'whyteboard.misc'],
py_modules = ['whyteboard'],
scripts = ['whyteboard.py'],
)
MANIFEST.in:
include *.txt
include whyteboard-help/*.*
recursive-include locale *.mo
recursive-include images *.png
当我运行“python setup.py install sdist”时,我得到一个不错的 .tar.gz ,其中包含“whyteboard-0.41”根文件夹,其中我的 locale/ images/ 和 Whyteboard-help/ 文件夹位于其中。这还有我的 Whyteboard.py 脚本,它从 Whyteboard 源代码包内启动我的程序。
所以:
whyteboard/
├── locale/
├── images
├── whyteboard-help/
├── whyteboard/
│ ├── __init__.py
│ └── other packages etc
├── whyteboard.py
├── README
├── setup.py
└── CHANGELOG
这反映了我的程序的源代码,一切都应该如此,并且是正确的。
但是,当我运行“python setup.py install”时,没有写入任何数据文件 - 只有“whyteboard”源包,并且whyteboard.py放置在/usr/local/lib/python2.6/dist-packages/中。
理想情况下,我希望在 dist-packages 中创建与 .tar.gz 文件中生成的目录结构相同的目录结构,因为这是我的程序期望查找其资源的方式。
我怎样才能“安装”来创建这个目录结构?据我所知,它似乎忽略了我的清单文件。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
MANIFEST.in
告诉 Distutils 在源代码分发中包含哪些文件,但它不会直接影响安装哪些文件。为此,您需要在setup.py
文件中包含适当的文件,通常为 软件包数据 或作为 附加文件。MANIFEST.in
tells Distutils what files to include in the source distribution but it does not directly affect what files are installed. For that you need to include the appropriate files in thesetup.py
file, generally either as package data or as additional files.我不明白为什么当我运行
python setup.py install
时我的MANIFEST.in
文件被忽略 - 结果是include_package_data=True
解决了问题。实际上并不需要package_data
选项。I couldn't figure out why my
MANIFEST.in
file was being ignored when I ranpython setup.py install
- turns outinclude_package_data=True
solves the problem. Thepackage_data
option isn't actually required.除了 Ned 的回答(触及核心问题)之外,还有一些注释:
Distutils 不会在
site-packages
(或dist-packages< /code>(Debian/Ubuntu 上的 /code>):如您所见,它们直接安装到
site-packages
中。因此,sdist 中包含的whyteboard-xx
目录在最终安装的形式中将不存在。这意味着您应该小心地命名您的
data_files
,以明确它们属于哪个项目,因为这些文件/目录直接安装到全局site-packages< /code> 目录,不在任何包含
whyteboard
目录内。或者您可以将数据放在
whyteboard
包的package_data
中(这意味着它需要位于该包内,即位于__init__.py
旁边) ),然后这就不是问题了。最后,在
py_modules
中同时拥有whyteboard.py
模块和whyteboard/__init__.py
包在py_modules
中并没有多大意义。代码>包。两者是互斥的,如果两者都有,导入时将忽略whyteboard.py
模块,转而使用同名的包。如果
whyteboard.py
只是一个脚本,并且不打算导入,那么您应该使用 scripts 选项,并将其从py_modules
中删除。Some notes in addition to Ned's answer (which hits on the core problem):
Distutils does not install Python packages and modules inside a per-project subdirectory within
site-packages
(ordist-packages
on Debian/Ubuntu): they are installed directly intosite-packages
, as you've seen. So the containingwhyteboard-xx
directory in your sdist will not exist in the final installed form.One implication of this is that you should be careful to name your
data_files
in a way that clarifies what project they belong to, because those files/directories are installed directly into the globalsite-packages
directory, not inside any containingwhyteboard
directory.Or you could instead make your data
package_data
of thewhyteboard
package (which means it needs to live inside that package, i.e. next to__init__.py
), and then this isn't a problem.Lastly, it doesn't make much sense to have both a
whyteboard.py
module inpy_modules
and awhyteboard/__init__.py
package inpackages
. The two are mutually exclusive, and if you have both, thewhyteboard.py
module will be ignored by imports in favor of the package of the same name.If
whyteboard.py
is just a script, and is not intended to be imported, then you should use the scripts option for it, and remove it frompy_modules
.您应该使用 setuptools:
这实际上并不是使用 MANIFEST 文件来完成这项工作,但它包含所有需要的文件。
You should use setuptools:
This is not actually using the MANIFEST file to do the job, but it includes all the needed files.
在 Mac OSX 上运行 python 2.6.1,除了在 setup.py 中使用 data_files 参数之外,我完全没有运气。 MANIFEST.in 的所有内容都只是导致文件包含在 dist 包中,但从未安装。我检查了其他一些包,它们确实使用 data_files 来指定其他文件。
目录树中的所有文件
我创建了一个简短的函数来帮助枚举data_files 期望的 (target_dir, [file list]) 格式的
:现在我可以在我的设置调用中调用它
:在那些树上安装。
Running python 2.6.1 on Mac OSX, I had absolutely no luck except by using the data_files parameter in setup.py. Everything with MANIFEST.in simply resulted in files being included in the dist package, but never installed. I checked some other packages and they were indeed using data_files to specify additional files.
I created a short function to help enumerate all the files from a directory tree in the
(target_dir, [file list]) format that data_files expects:
Now I can just call this inside my setup call:
And everything in those trees gets installed.
最小已发布的可运行示例
关键要点:只有
MANIFEST.in
对我有用,package_data
没有。在 Ubuntu 19.10、Python 3.7.5、wheel==0.32.3、setuptools==41.1.0、twine==3.1.1 上测试。
最终用户如何使用 https://pypi.org/project/python 中的包-sample-package-with-data/:
预期输出:
维护者如何发布它:
实际文件:
设置中的 MANIFEST
python-sample-package-with-data
python_sample_package_with_data/__init__.py
python_sample_package_with_data/mydata.txt
.。 py
参考书目:
Minimal published runnable example
Key takeaway: only
MANIFEST.in
worked for me,package_data
did not.Tested on Ubuntu 19.10, Python 3.7.5, wheel==0.32.3, setuptools==41.1.0, twine==3.1.1.
How end users use the package from https://pypi.org/project/python-sample-package-with-data/:
Expected output:
How maintainers publish it:
The actual files:
MANIFEST.in
python-sample-package-with-data
python_sample_package_with_data/__init__.py
python_sample_package_with_data/mydata.txt
setup.py
Bibliography: