首页 > 解决方案 > Python setuptools 无法在 user_config_dir 中安装 data_files

问题描述

我希望从我的包中安装的子目录中有一组 sql 文件。

project\
thetask\
    __init__.py
    MainThing.py
sql\
    foo\thingone.sql
    foo\thingtwo.sql
    bar\thingone.sql
    bar\thingtwo.sql
README.md
MANIFEST.in

MANIFEST.in的仅包含recursive-include sql *.sql.

setup.py尝试将文件安装在user_config_dirappdirs.

import setuptools
import os

from appdirs import AppDirs
APP_DIRS = AppDirs("table_builder", "thetask")

def long_desc(path_to_md):
    """
    Use markdown for description on devpi server.
    """
    with open(path_to_md, "r") as _fh:
        return _fh.read()

setuptools.setup(
    name="mything-thetask",
    version="0.1a",
    description="Tools for building TheTask tables.",
    long_description=long_desc("README.md"),
    long_description_content_type="text/markdown",
    author="Someguy SomeGuysLastName",
    author_email="Someguy.SomeGuysLastName@mything.com",
    license="Proprietary",
    install_requires=[
        "xlrd",
        "pyodbc",
        "appdirs",
        ],
    include_package_data=True,
    packages=setuptools.find_packages(),
    scripts=[
        "foo.py",
        "bar.py",
    ],
    data_files=[
        (APP_DIRS.user_config_dir, [
        "sql\\foo\\*.sql",
        "sql\\bar\\*.sql"
        ])
    ],
)

thetask\\table_builder目录是在我的目录中创建的AppData\\Local,但install_data失败并显示:

    running install_data
    error: can't copy 'sql\foo\*.sql': doesn't exist or not a regular file

    ----------------------------------------
Command "c:\users\someguy\projects\testinstall\venv\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\someguy\\AppData\\Local\\Temp\\pip-install-bmlgs1fl\\mything-thetask\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\someguy\AppData\Local\Temp\pip-record-ia0ycbsc\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\someguy\projects\testinstall\venv\include\site\python3.7\mything-thetask" failed with error code 1 in C:\Users\someguy\AppData\Local\Temp\pip-install-bmlgs1fl\mything-thetask\
command failed

我希望看到的所有文件都在包的sql目录中.zip。我哪里错了?

UPDATE:我尝试使用特定的 sql 文件而不是 in 中的通配符data_files,这消除了错误,但没有在AppData\\Local. 这有点令人沮丧。

标签: pythonsetuptools

解决方案


推荐阅读