简体   繁体   中英

setup.py package bundled file is not installed

I have a file which correctly appears inside the source distribution and the wheel but it does not appear in site-packages when installed.

My project structure looks like this:

|-- README.md
|-- config
|   `-- log.ini
|-- oauc
|   |-- __init__.py
|   |-- odoo_driver.py
|   `-- page.py
|-- requirements.txt
`-- setup.py

The file in question is config/log.ini .

My setup looks like this:

import setuptools

setuptools.setup(
    name='oauc',
    version='0.0.1',
    packages=setuptools.find_packages(),
    data_files=[('oauc', ['config/log.ini'])],
    include_package_data=True
)

And here is the result oauc-0.0.1.tar.gz :

|-- PKG-INFO
|-- README.md
|-- config
|   `-- log.ini
|-- oauc
|   |-- __init__.py
|   |-- odoo_driver.py
|   `-- page.py
|-- oauc.egg-info
|   |-- PKG-INFO
|   |-- SOURCES.txt
|   |-- dependency_links.txt
|   |-- requires.txt
|   `-- top_level.txt
|-- setup.cfg
`-- setup.py

It looks fine.

However, when I install with pip install src/dist/oauc-0.0.1.tar.gz (src is a symlink to project dir), the resulting install venv/lib/python3.7/site-packages/oauc does not include the file:

|-- __init__.py
|-- __pycache__
|   |-- __init__.cpython-37.pyc
|   |-- odoo_driver.cpython-37.pyc
|   `-- page.cpython-37.pyc
|-- odoo_driver.py
`-- page.py

And I think it should be there. In my init file:

import logging.config
import pkg_resources

logging.config.fileConfig(pkg_resources.resource_filename(__name__, 'config/log.ini'))

The call pkg_resources.resource_filename(__name__, 'config/log.ini') returns venv/lib/python3.7/site-packages/oauc/config/log.ini .

How do I make the log.ini file bundled with the package accessible at runtime and how do I find his location ?

I moved the file inside the package, used package_data rather than data_files, added a Manifest.in file. I guess data_files land somewhere else. Anyway, putting y configuration files in my package isn't too weird. So the final result is:

Structure:

|-- MANIFEST.in
|-- README.md
|-- oauc
|   |-- __init__.py
|   |-- config
|   |   |-- __init__.py
|   |   `-- log.ini
|   |-- odoo_driver.py
|   `-- page.py
|-- requirements.txt
`-- setup.py

MANIFEST.in:

include oauc/config/log.ini

setup.py:

import setuptools

setuptools.setup(
    name='oauc',
    version='0.0.1',
    packages=setuptools.find_packages(),
    package_data={'config': ['log.ini']},
    include_package_data=True
)

I guess that you're not supposed to query files specified by attribute data_files with pkg_resources are they're not inside the package and that was my primary mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM