Search code examples
pythonpippackagepypi

My package on PyPi cannot find relevant files


I'm trying to upload my first package on PyPi. Everything seems to be good except my function cannot access the relevant files within the package. Error is as follows.

File "/Users/my_username/anaconda/lib/python3.6/site-packages/deepcut/deepcut.py", line 134, in tokenize
with open('weight/object.pk', 'rb') as handle:
FileNotFoundError: [Errno 2] No such file or directory: 'weight/object.pk'

I've checked that pip actually installed my files with the package. Here is what is in my installed directory /Users/my_username/anaconda/lib/python3.6/site-packages/deepcut

__init__.py
deepcut.py
__pycache__
  ...
weight
  best_cnn.h5
  object.pk

The folder I used to create package consist of

LICENCE.txt
MANIFEST
MANIFEST.in
README.rst
setup.dfg
setup.py
deepcut
  __init__.py
  deepcut.py
  weight
    best_cnn.h5
    object.pk  

The content of setup file is as follows.

from distutils.core import setup
import setuptools

setup(
  name = 'deepcut',
  packages = ['deepcut'], 
  package_dir={'deepcut': 'deepcut'},
  package_data={'deepcut': ['weight/*']},
  include_package_data=True,
  version = '0.5.0.13',
  install_requires=['keras', 'pandas', 'scipy', 'numpy'],
  license='MIT',
  description = 'A Thai word tokenization library using Deep Neural Network',
  author = 'Rakpong Kittinaradorn',
  author_email = '[email protected]',
  url = 'https://github.com/rkcosmos/deepcut',
  download_url = 'https://github.com/rkcosmos/deepcut/package/0.5.zip', 
  keywords = ['thai word segmentation deep learning neural network development'],
  classifiers = ['Development Status :: 3 - Alpha'],
)

and MANIFEST.in

# Include the license file
include LICENSE.txt
include README.rst

# Include the data files
recursive-include deepcut *

Solution

  • You can try using an absolute path instead.

    # this will be the path that the file is stored in
    # which for you should be /Users/my_username/anaconda/lib/python3.6/site-packages/deepcut/
    path_to_module = os.path.dirname(__file__) 
    
    # now just join it with the file in the weight folder
    weight_path = os.path.join(path_to_module, "weight", "object.pk")
    with open(weight_path, 'rb') as handle:
        pass