我正在尝试将一个简单的python包上传到PypI。为了进行测试,我首先上传到test.pypi.org。当我使用pip安装此软件包并使用它时,出现错误FileNotFoundError: [Errno 2] File b'../data/spam_collection.csv' does not exist: b'../data/spam_collection.csv'
。
我参考了StackOverflow和文档here和here上的其他类似问题,实现了以下内容。我做了很多尝试,因为您可以看到这是我的软件包的版本11。我在这里做错了什么?
我使用package_data上传csv文件。
setup.py
import setuptools
import string
import ast
import nltk
import pandas as pd
from nltk.corpus import stopwords
from nltk import sent_tokenize
from nltk import ngrams
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="spamclassifier",
version="0.1.1",
author="#####",
author_email="###########",
description="A bigram approach for classifying Spam and Ham messages",
long_description=long_description,
long_description_content_type="text/markdown",
url="#############",
packages=setuptools.find_packages(),
include_package_data=True,
package_data={'data': ['data/spam_collection.csv']},
install_requires=["nltk", "pandas"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
我的项目结构
我如何在python文件中称呼此CSV
def classify(self):
fullCorpus = pd.read_csv("../data/spam_collection.csv", sep="\t", header=None)
fullCorpus.columns = ["lable", "body_text"]
MANIFEST.in
include README.md
include LICENSE
include data/spam_collection.csv
使用pip安装python软件包后,我运行pip show -f spamclassifier
列出了软件包中的文件,但未列出csv文件。输出为
Name: spamclassifier
Version: 0.1.3
Summary: A bigram approach for classifying Spam and Ham messages
Home-page: XXXXXXXX
Author: XXXXXXX
Author-email: XXXXXX
License: UNKNOWN
Location: /home/kabilesh/PycharmProjects/TestPypl3/venv/lib/python3.6/site-packages
Requires: pandas, nltk
Required-by:
Files:
spamclassifier-0.1.3.dist-info/INSTALLER
spamclassifier-0.1.3.dist-info/LICENSE
spamclassifier-0.1.3.dist-info/METADATA
spamclassifier-0.1.3.dist-info/RECORD
spamclassifier-0.1.3.dist-info/WHEEL
spamclassifier-0.1.3.dist-info/top_level.txt
spamclassifier/SpamClassifier.py
spamclassifier/__init__.py
spamclassifier/__pycache__/SpamClassifier.cpython-36.pyc
spamclassifier/__pycache__/__init__.cpython-36.pyc
答案 0 :(得分:0)
尝试一下:
packages=['spamclassifier'],
package_dir={'spamclassifier': 'spamclassifier'},
package_data={'spamclassifier': ['data/*']},
include_package_data=True
将其他所有内容保持不变。希望对您有帮助