这个“setup.py”有什么问题?
我在让 setup.py
正确执行 sdist
方面遇到了问题。我把它归结为这一点。我有以下目录结构:
my_package\
my_subpackage\
__init__.py
deep_module.py
__init__.py
module.py
setup.py
这是我在 setup.py
中的内容:(
#!/usr/bin/env python
from distutils.core import setup
import distutils
setup(
name='a',
version='0.1',
description='a',
author='a',
author_email='[email protected]',
url='http://a.org',
packages=['my_package','my_package.my_subpackage'],
package_dir={'': '..'},
license= "a",
long_description = 'aaa',
)
'aaa'
只是占位符。)
无论如何,当我这样做时它工作正常setup.py install
,但是当我尝试执行 setup.py sdist
时,发生了一些奇怪的事情:
A
MANIFEST
文件是创建。在现有
my_package
文件夹内部创建my_package
文件夹的副本(尽管它丢失了一些我设置的相关文件) )创建了一个
dist
文件夹,里面有一个 zip 文件,里面有一个带有包名称的文件夹,但在该文件夹内没有像我这样的整个包希望但只有两个文件,setup.py
和PKG-INFO
。
我做错了什么?如何使 sdist
工作?
I've been having problems withe getting setup.py
to do the sdist
thing correctly. I boiled it down to this. I have the following directory structure:
my_package\
my_subpackage\
__init__.py
deep_module.py
__init__.py
module.py
setup.py
And here's what I have in setup.py
:
#!/usr/bin/env python
from distutils.core import setup
import distutils
setup(
name='a',
version='0.1',
description='a',
author='a',
author_email='[email protected]',
url='http://a.org',
packages=['my_package','my_package.my_subpackage'],
package_dir={'': '..'},
license= "a",
long_description = 'aaa',
)
(The 'aaa'
stuff is just placeholder.)
Anyway, it works okay when I do setup.py install
, but when I try to do setup.py sdist
, a few curious things happen:
A
MANIFEST
file is created.A copy of the
my_package
folder is created inside the existingmy_package
folder (though it misses a few of the setup-related files I think.)A
dist
folder is created, inside it a zipfile, inside that a folder with the package name, but inside that folder there isn't the whole package like I hoped but only two files,setup.py
andPKG-INFO
.
What am I doing wrong? How do I make sdist
work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题在这里得到了很好的解释:
正如评论所指出的,这个错误(设计错误)实际上是在 distutils 中——setuptools 只是无法修复它(如果你使用 svn,情况实际上会好一点)。
我可以在您观察时重现您的问题,即稍微缩短文件名,我有:
并且运行 python setup.py sdist 会产生(以及警告):
一种解决方案是更改目录布局如下(来自当前的 mypack 目录):
所以得到:(
并删除其中一个警告,即关于 README 的警告——关于丢失 MANIFEST.in 的警告显然仍然存在;-)。还将 setup.py 的一行更改为:
现在,在
python setup.py sdist
之后,您确实得到了一个不错的 tarball:当然,MANIFEST 文件仍然在您当前的目录中创建,但我希望这是不是问题。
The problem is well explained here:
As comments point out, the bug (misdesign) is actually in distutils -- setuptools just fails to fix it (if you're using svn, things are actually a bit better).
I can reproduce your problem as you observe it, i.e., shortening file names a bit, I have:
and running
python setup.py sdist
produces (as well as warnings):One solution is to change the directory layout as follows (from the current mypack dir):
so getting:
(and getting rid of one of the warnings, the one about README -- the one about missing MANIFEST.in clearly remains;-). Also change one line of setup.py to:
Now, after
python setup.py sdist
, you do get a decent tarball:the MANIFEST file is still created in your current directory of course, but I hope that's not a problem.
而不是这个:
尝试这个:
您实际上不需要自述文件,它只是为了说明项目文件夹的根目录中包含哪些内容。
===编辑========================================
我应该详细说明。运行它后,您的目录应如下所示:
使用 dist 目录下的包进行分发。
Instead of this:
Try this:
You don't actually need a README, it's just for illustrative purpose for what kind of things sit in the root directory of your project's folder.
=== EDIT ======================================
I should elaborate. After you run it your directory should then look something like this:
Use the package under the dist directory to distribute.