这是我编写setup.py
文件的模块的树结构:
ls .
LICENSE
README.md
bin
examples
module
scratch
setup.py
tests
tox.ini
我将setup.py
配置如下:
from setuptools import setup, find_packages
setup(
name="package_name",
version="0.1",
packages=find_packages(),
install_requires=[
# [...]
],
extras_require={
# [...]
},
tests_require={
'pytest',
'doctest'
},
scripts=['bin/bootstrap'],
data_files=[
('license', ['LICENSE']),
],
# [...]
# could also include long_description, download_url, classifiers, etc.
)
如果我从我的python环境(也是virtualenv)安装软件包
pip install .
LICENSE
文件已正确安装。
但是正在运行tox
:
[tox]
envlist = py27, py35
[testenv]
deps =
pytest
git+https://github.com/djc/couchdb-python
docopt
commands = py.test \
{posargs}
我收到此错误:
running install_data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data/license
error: can't copy 'LICENSE': doesn't exist or not a regular file
从setup.py中删除data_files
部分可使tox
正常运行。
答案 0 :(得分:1)
您的问题是,setuptools无法在用于构建源发行版的文件中找到“ LICENSE”文件。您有2个选项,可以告诉setuptools包含该文件(均已在此处指出):
MANIFEST.in
文件(例如https://github.com/pypa/sampleproject/)include_package_data=True
。由于https://pypi.org/project/check-manifest/,使用MANIFEST.in
通常更容易验证,因此可以使用自动化来验证事情确实正确(如果使用的是Git或SVN之类的VCS)。 / p>
pip install .
使用python setup.py bdist_wheel
构建车轮,只需按照车轮规范https://www.python.org/dev/peps/pep-0427/
tox
使用python setup.py sdist
构建源分发,然后使用python setup.py install
解压缩并安装。
这可能是您行为不同的原因。
答案 1 :(得分:0)
我的软件包中有一些资源文件,我在执行过程中会使用它们。为了使安装程序将它们存储在带有python代码的程序包中,我使用include_package_data=True
,并使用importlib.resources
访问它们。您可以将backport用于3.7之前的Python版本或其他库。
在每个发行版之前,我都有一个脚本进行验证,以确保我需要的所有文件都放在bdist
滚轮中,以确保所有内容都在适当的位置。