samruddhi ingale
samruddhi ingale

Reputation: 1

access data files in site-package

I have created a python package named (my_package). In that package I have used data.pt file (ml model file) in my python modules and it worked successfully.

then I built it's wheel file "my_package.whl" and installed the package in another machine via pip command.

command : "pip install my_package.whl" then it get error as :

error : [Errno 2] No such file or directory:'/home/samruddhiingle/Desktop/Gitlab/project/venv/lib/python3.8/site-packages/my_package/data/data.pt'

I've tried a variety of methods

  1. get absolute path and relative path of data.pt file
  2. use of : file_path = pkg_resources.resource_filename('my_package', '/data/data.pt')

This seems like it ought to be a trivial, common problem. Yet I can't seem to figure it out. Part of the problem is that my data files are not .py files, so I can't use import functions and the like.

Any suggestions?

Right now my package directory looks like:

my_package

__init__.py
module1.py
module2.py
data/   
   data.pt

Upvotes: 0

Views: 979

Answers (1)

samruddhi ingale
samruddhi ingale

Reputation: 1

The issue has been solved. I have accessed all non python files in .whl file by mentioning it in setup.cfg.

the setup.cfg file is as follows :

    [metadata]
    name = my_package
    version = 0.0.1
    author = xxx
    author_email = [email protected]
    description = A small machine learning package
    long_description = file: README.md
    long_description_content_type = text/markdown
    classifiers =
        Programming Language :: Python :: 3
        License :: OSI Approved :: MIT License
        Operating System :: OS Independent

    [options]
    install_package_data = True
    package_dir =
        = src
    packages = find:
    python_requires = >=3.6

    [options.package_data]
    my_packagestrong text = models/*.pt, data/*.json, data_preprocessor/*.json

    [options.packages.find]`enter code here`
    where = src

Upvotes: 0

Related Questions