0

I am packaging my app where I need to load a config.yaml file which resides in my project. After doing pip install I am seeing the file is present in package but it's not picking up the file.

My directory structure

.
├── config_loader
│   ├── config.yaml
│   ├── __init__.py
│   └── loader.py
├── MANIFEST.in
├── setup.py

My setup.py file

from setuptools import setup, find_packages

base_requirements = [
    'pyyaml',
    ]

setup(
    name="Test",
    version="1.1.1",
    description="Test app",
    python_requires=">=3.8",
    keywords="python, Test app",
    packages=find_packages(),
    package_data={
        'config_loader': ['*.yaml'],
    },
    install_requires=base_requirements,
)

I created whl file using

python setup.py sdist bdist_wheel
# installing package
pip3 install dist/Test-1.1.1-py3-none-any.whl

After installation is complete I can check file is present there

$ ls /home/anaconda3/envs/test/lib/python3.8/site-packages/config_loader/
config.yaml  __init__.py  loader.py    __pycache__/

But when I run the package from command line I am getting following error

$ python3 -m config_loader.loader.py
Traceback (most recent call last):
  File "/home/anaconda3/envs/test/lib/python3.8/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/anaconda3/envs/test/lib/python3.8/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/anaconda3/envs/test/lib/python3.8/site-packages/config_loader/loader.py", line 3, in <module>
    with open("config.yaml", "r") as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'config.yaml'

If you are wondering what's inside loader.py

import yaml

with open("config.yaml", "r") as stream:
    try:
        print(yaml.safe_load(stream))
    except yaml.YAMLError as exc:
        print(exc)

Init file is empty. Can someone help me with this. Thanks in advance.

Pranjal Doshi
  • 862
  • 11
  • 29

0 Answers0