Python 在 setup.py 中需要什么选项才能在正确的目录中创建包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15839520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What option do I need in setup.py to create the package in the right directory?
提问by Alex
I am using setup.pyto create a python package, which I want to install via pip. To correctly install the files under
我正在使用setup.py创建一个 python 包,我想通过pip. 正确安装下的文件
lib/python2.7/site-packages/<package-name>
I used the following option in setup.py:
我在以下选项中使用了setup.py:
'package_dir': {'':'lib'}
as described herebut get an error
如此处所述,但出现错误
error: package directory 'lib' does not exist
Well, there is no such directory as I want the currentdirectory to be installed as package libor whatever. I also tried to use
好吧,没有这样的目录,因为我希望将当前目录安装为包lib或其他任何目录。我也尝试使用
'package_dir': {'mycode':''}
which installes the code directly in
将代码直接安装在
lib/python2.7/site-packages/
and not under
而不是在
lib/python2.7/site-packages/<package-name>
What am I doing wrong, and where is this documented? I might overlooked the documentation of this basic feature as the documentation for setup.pyis 'suboptimal'.
我做错了什么,这在哪里记录?我可能忽略了这个基本功能的文档,因为文档setup.py是“次优”的。
采纳答案by Alex
The description to how to do this an be found in the distribute documentation... Within a directory containing all of the project (TowelStuff/in the given example) you specify the name of the actual module (towelstuff/). To include this as yourmodule you need to add the following line in setup.py:
如何做到这一点的描述可以在分发文档中找到......在包含所有项目的目录中(TowelStuff/在给定的示例中),您指定实际模块的名称 ( towelstuff/)。要将其包含为您的模块,您需要添加以下行setup.py:
'packages': ['towelstuff']
After having created the sdist (from within TowelStuff/), the installation of this package will install it under site-packages/towelstuff, which can be imported as usual (from towelstuff import ...).
创建 sdist(从 内TowelStuff/)后,此包的安装会将其安装在 下site-packages/towelstuff,可以像往常一样导入(from towelstuff import ...)。

