Python distutils 错误:“[目录]...不存在或不是常规文件”
让我们采用以下项目布局:
$ ls -R .
.:
package setup.py
./package:
__init__.py dir file.dat module.py
./package/dir:
tool1.dat tool2.dat
setup.py
的内容如下:
$ cat setup.py
from distutils.core import setup
setup(name='pyproj',
version='0.1',
packages=[
'package',
],
package_data={
'package': [
'*',
'dir/*',
],
},
)
如您所见,我想在 package/
和 中包含所有非 Python 文件>package/dir/
目录。但是,运行 setup.py install 会引发以下错误:
$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/package
copying package/module.py -> build/lib/package
copying package/__init__.py -> build/lib/package
error: can't copy 'package/dir': doesn't exist or not a regular file
什么给出了?
Let's take the following project layout:
$ ls -R .
.:
package setup.py
./package:
__init__.py dir file.dat module.py
./package/dir:
tool1.dat tool2.dat
And the following content for setup.py
:
$ cat setup.py
from distutils.core import setup
setup(name='pyproj',
version='0.1',
packages=[
'package',
],
package_data={
'package': [
'*',
'dir/*',
],
},
)
As you can see, I want to include all non-Python files in package/
and package/dir/
directories. However, running setup.py install
would raise the following error:
$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/package
copying package/module.py -> build/lib/package
copying package/__init__.py -> build/lib/package
error: can't copy 'package/dir': doesn't exist or not a regular file
What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的
package_data
中,您的'*'
glob 将匹配package/dir
本身,并尝试将该目录复制为文件,从而产生失败。找到一个与目录package/dir
不匹配的 glob,按照以下方式重写您的setup.py
:根据您的示例,这只是更改
'*'
到'*.dat'
,尽管您可能需要进一步优化您的 glob,但只需确保它不会匹配'dir'
In your
package_data
, your'*'
glob will matchpackage/dir
itself, and try to copy that dir as a file, resulting in a failure. Find a glob that won't match the directorypackage/dir
, rewriting yoursetup.py
along these lines:Given your example, that's just changing
'*'
to'*.dat'
, although you'd probably need to refine your glob more than that, just ensure it won't match'dir'
您可以使用 Distribute 而不是 distutils。它的工作原理基本相同(在大多数情况下,您不必更改 setup.py),并且它为您提供了 except_package_data 选项:
You could use Distribute instead of distutils. It works basically the same (for the most part, you will not have to change your setup.py) and it gives you the exclude_package_data option:
我创建了一个函数,它为我提供了我需要的所有文件
,并将其用作
package_data
的参数I created a function that gives me all the files that I need
And used that as arugment for
package_data
不太清楚为什么,但经过一些故障排除后,我意识到重命名名称中带有点的目录可以解决问题。例如
注意:我使用的是Python 2.7.10,SetupTools 12.2
Not quite sure why, but after some troubleshooting I realised that renaming the directories that had dots in their names solved the problem. E.g.
Note: I'm using Python 2.7.10, SetupTools 12.2