Python:具有多个 setup.py 文件的多个包
我很难构建我的 Python setup.py 文件来执行我想要的操作。我有一个像这样设置的包:
somestuff_root/
setup.py
myutils/
__init__.py
a/
__init__.py
somestuff.py
我有另一个像这样的包设置:
otherstuff_root/
setup.py
myutils/
__init__.py
b/
__init__.py
otherstuff.py
所以东西在我的 site-packages/ 目录中组织起来,如下所示:
myutils/
a/
somestuff.py
b/
otherstuff.py
这正是我用 pip 安装它们后想要的。
我的问题是卸载第二个包(使用 pip)也会清除第一个包 - 这不是我想要发生的事情。我希望它只是删除 myutils.b 并将 myutils.a 保留在原处。
我怀疑我将多个 init.py 文件与 myutils/ 文件夹混淆了,但我不确定如何让这些文件正常工作。
--
还发现了这个有用的页面:
http://www.sourceweaver.com/musings /posts/python-namespace-packages
I'm having a hard time constructing my Python setup.py files to do what I want. I have one pacakge set up like this:
somestuff_root/
setup.py
myutils/
__init__.py
a/
__init__.py
somestuff.py
I have another package setup like this:
otherstuff_root/
setup.py
myutils/
__init__.py
b/
__init__.py
otherstuff.py
so things are organized in my site-packages/ directory like:
myutils/
a/
somestuff.py
b/
otherstuff.py
which is exactly what I want after installing them both with pip.
My problem is that uninstalling the second package (with pip) also wipes out the first one -- this is not what I want to happen. I would like it just to remove myutils.b and keep myutils.a where it is.
I suspect I'm confusing things with having multiple init.py files in with myutils/ folders, but I'm not sure how else to get these to work properly.
--
Also found this helpful page:
http://www.sourceweaver.com/musings/posts/python-namespace-packages
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,那么您尝试设置的是一个命名空间包(一个包含其他单独安装的包的空包),它是一个 setuptools 的功能。
使用作为
namespace_packages
参数的命名空间的包列表调用setuptools.setup()
。然后,创建仅包含以下内容的
myutils/__init__.py
:最后,在
myutils/a/__init__.py
和myutils/b/__init__.py
中code> 调用pkg_resources.declare_namespace('myutils')
,这可确保在先安装较低级别的包时创建命名空间。我很确定这就是它的工作原理。我仍在学习设置工具,因此如果我错了,非常感谢纠正。
If I'm understanding this correctly, what you are trying to set up is a namespace package (an empty package that contains other, separately installed packages), which is a feature of setuptools.
Call
setuptools.setup()
with a list of packages that are namespaces for thenamespace_packages
argument.Then, create
myutils/__init__.py
containing only the following:Finally, in
myutils/a/__init__.py
andmyutils/b/__init__.py
callpkg_resources.declare_namespace('myutils')
, which ensures that the namespace is created if a lower-level package is installed first.I'm pretty sure that's how it works. I'm still learning setuptools so if I'm wrong, corrections are much appreciated.