无法将csv文件上载到test.pypi.org网站

2024-09-22 14:39:11 发布

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

我试图上传一个简单的python包到PypI。为了测试这个,我首先上传到test.pypi.org。当我用pip安装并使用这个包时,我得到了错误FileNotFoundError: [Errno 2] File b'../data/spam_collection.csv' does not exist: b'../data/spam_collection.csv'。 我参考了有关StackOverflow和文档herehere的其他类似问题实现了以下内容。我试了很多次,你可以看到这是我的软件包的第11版。我做错什么了?你知道吗

我使用包数据上传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",
    ],
)

My project structure

enter image description here

How I call this csv in the python file

 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

Tags: pip文件csvpyimportinfodatainclude
1条回答
网友
1楼 · 发布于 2024-09-22 14:39:11

试试这个:

packages=['spamclassifier'],
package_dir={'spamclassifier': 'spamclassifier'},
package_data={'spamclassifier': ['data/*']},
include_package_data=True

其他一切保持不变。希望有帮助

相关问题 更多 >