0

I am having a lot of issues when uploading a PyPi package, because I have a package that reads information from a TXT file in another directory. This is my project structure:

Structure

I can read the files if I do it using my own package from the PyCharm project, but the problem is when I upload it to PyPi and I import is as a pip package.

I read the file in local this way:

tickers = pd.read_csv('../data/tickers.csv')

But that does not work when I install the package using pip.

I have been trying to configure setup.py, but with no succeed, because when I install the package uploaded to PyPi using pip, I get an error like this:

FileNotFoundError: [Errno 2] No such file or directory: 'data/user-agent-list.txt'

This is what I have in my setup.py related to those external files contained in the data/ directory:

setup.py lines

I also have a MANIFEST.in to include the data files:

MANIFEST.in

I hope the information I provided is enough for you to let me know how can I fix this... To give you extra information, I am following this tutorial to upload my package to PyPi, but the error has nothing to do with it.

Thank you!

alvarobartt
  • 453
  • 5
  • 15
  • Is the path 'data/tickers.csv' correct? Or it needs to be starts with double dot ('../darta/tickers.csv')? – Alex Kroll Dec 13 '18 at 12:03
  • @AlexKroll yes, the filepath that works when I execute it locally is ../data/tickers.csv. But I don't know if I should use the same for the PyPi package to work :( – alvarobartt Dec 13 '18 at 12:08
  • Possible duplicate of [How to read a (static) file from inside a Python package?](https://stackoverflow.com/questions/6028000/how-to-read-a-static-file-from-inside-a-python-package) – phd Dec 13 '18 at 16:09
  • https://stackoverflow.com/search?q=%5Bsetuptools%5D+access+package+data – phd Dec 13 '18 at 16:10
  • @alvarobartt - If you found my answer helpful please mark the answer with the green tick on the left. – sophros Feb 07 '19 at 14:03

1 Answers1

0

I am wondering if the issue is not related to the path you are using here:

pd.read_csv('../data/tickers.csv')

It refers to the path that is relative to the base execution path of the script that is using your module. Try using a non-relative path. You may also want to use the install path as suggested in this question.

sophros
  • 14,672
  • 11
  • 46
  • 75