FileNotFoundError: [Errno 2] when packaging for PyPI

前端 未结 1 2054
忘掉有多难
忘掉有多难 2020-12-21 05:19

I have uploaded a simple python package in https://test.pypi.org. When I download this with pip and try yo run I get FileNotFoundError: [Errno 2] File b\'data/spam_col

相关标签:
1条回答
  • 2020-12-21 05:56

    Your script is attempting to load the spam_collection.csv file from a relative path. Relative paths are loaded relative to where python is being invoked, not where the source file is.

    This means that when you're running your module from the bigramspamclassifier directory, this will work. However, once your module is pip-installed, file will no longer be relative to where you're running your code from (it will be buried somewhere in your installed libraries).

    You can instead load relative to the source file by doing something like:

    import os
    this_dir, this_filename = os.path.split(__file__)
    DATA_PATH = os.path.join(this_dir, "data", "spam_collection.csv")
    fullCorpus = pd.read_csv(DATA_PATH, sep="\t", header=None)
    
    0 讨论(0)
提交回复
热议问题