python打包和分发项目

时间:2019-11-03 14:38:10

标签: python

我想打包python项目,但是当我打包该项目并且该项目中的python文件需要使用数据文件时,会出现“ FileNotFoundError”。下图是我的项目结构:enter image description here

enter image description here

enter image description here

setup.py:

from setuptools import setup, find_packages

# To use a consistent encoding
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()


setup(
    name='NERChinese',
    version='0.0.6',

    description='基于BiLSTM-CRF的字级别中文命名实体识别模型',
    long_description=long_description,
    long_description_content_type='text/markdown',

    # The project's main homepage.
    url='https://github.com/cswangjiawei/Chinese-NER',

    # Author details
    # author='wangjiawei',
    # author_email='cswangjiawei@163.com',

    # Choose your license
    # license='MIT',

    # What does your project relate to?
    keywords='Named-entity recognition using neural networks',

    # You can just specify the packages manually here if your project is
    # simple. Or you can use find_packages().
    packages=find_packages(),

    zip_safe=False,
    package_data={
    'NERChinese': ['data/*'],
},
)

'FileNotFoundError:[错误2]没有这样的文件或目录:'data / msra_train.txt'在'with open(train path,R',encoding ='utf-8')as F1:'in中出现utils.py文件正在运行。我应该如何打包数据文件

1 个答案:

答案 0 :(得分:0)

打开时似乎没有指定正确的路径,您可以尝试以下方法:

max

通过这种方式,它与包的模块有关,而不与调用它的位置有关。

如果它不起作用,可以检查站点包装中是否包含数据?