我在PyPi上的包找不到相关文件

2024-10-03 23:20:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把我的第一个软件包上传到PyPi上。一切似乎都很好,除了我的功能无法访问包中的相关文件。错误如下。你知道吗

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'

我已经检查过pip是否真的安装了我的文件包。下面是我的安装目录/Users/my\u username/anaconda/lib/python3.6/site-packages/deepcut中的内容

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

我用来创建包的文件夹包括

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

安装文件的内容如下。你知道吗

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 = 'r.kittinaradorn@gmail.com',
  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'],
)

以及清单.in你知道吗

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

# Include the data files
recursive-include deepcut *

Tags: 文件inpycompackagedataobjectinclude
1条回答
网友
1楼 · 发布于 2024-10-03 23:20:50

您可以尝试改用绝对路径。你知道吗

# 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

相关问题 更多 >