我在https://test.pypi.org中上传了一个简单的python包。当我用pip下载这个并试着运行时,我得到了FileNotFoundError: [Errno 2] File b'data/spam_collection.csv' does not exist: b'data/spam_collection.csv'
。之前我在打包时上传csv文件时遇到了问题。请看Could not upload csv file to test.pypi.org中我的问题。现在,在用pip安装包之后,我运行pip show -f bigramspamclassifier
。我得到csv文件列表。因此,我相信文件已经上传了。我认为问题在于如何读取包中python文件中的文件。csv文件的路径应该是什么SpamClassifier.py?你知道吗
pip show -f bigramspamclassifier
Version: 0.0.3
Summary: A bigram approach for classifying Spam and Ham messages
Home-page: ######
Author: #####
Author-email: #######
Location: /home/kabilesh/PycharmProjects/TestPypl3/venv/lib/python3.6/site-packages
Requires: nltk, pandas
Required-by:
Files:
bigramspamclassifier-0.0.3.dist-info/INSTALLER
bigramspamclassifier-0.0.3.dist-info/LICENSE
bigramspamclassifier-0.0.3.dist-info/METADATA
bigramspamclassifier-0.0.3.dist-info/RECORD
bigramspamclassifier-0.0.3.dist-info/WHEEL
bigramspamclassifier-0.0.3.dist-info/top_level.txt
bigramspamclassifier/SpamClassifier.py
bigramspamclassifier/__init__.py
bigramspamclassifier/__pycache__/SpamClassifier.cpython-36.pyc
bigramspamclassifier/__pycache__/__init__.cpython-36.pyc
bigramspamclassifier/data/spam_collection.csv
My project file structure
Path to csv in SpamClassifier.py file #This what I want to know
def classify(self):
fullCorpus = pd.read_csv("data/spam_collection.csv", sep="\t", header=None)
fullCorpus.columns = ["lable", "body_text"]
您的脚本正在尝试从相对路径加载
spam_collection.csv
文件。相对路径是相对于调用python
的位置加载的,而不是源文件所在的位置。你知道吗这意味着当您从
bigramspamclassifier
目录运行模块时,这将起作用。然而,一旦您的模块被pip
安装,文件将不再与您运行代码的位置相关(它将被埋藏在您安装的库中的某个地方)。你知道吗您可以通过执行以下操作相对于源文件进行加载:
相关问题 更多 >
编程相关推荐