【问题标题】:My package on PyPi cannot find relevant files我在 PyPi 上的包找不到相关文件
【发布时间】:2017-11-26 12:42:01
【问题描述】:

我正在尝试在 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_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'],
)

和 MANIFEST.in

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

# Include the data files
recursive-include deepcut *

【问题讨论】:

    标签: python pip package pypi


    【解决方案1】:

    您可以尝试使用绝对路径。

    # 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
    

    【讨论】:

    • 那只对我有用,但其他人下载我的包怎么样?
    • 应该不是问题——path_to_module 是根据包的安装位置动态计算的。
    猜你喜欢
    • 1970-01-01
    • 2020-04-21
    • 2019-09-06
    • 2021-12-11
    • 2021-11-09
    • 2022-01-20
    • 2014-04-21
    • 2020-02-14
    • 1970-01-01
    相关资源
    最近更新 更多