I have packaged a python file with with setuptools, unfortunately I encounter FileNotFound when I import the project in other directory. What is the correct way of importing a text file inside a script?
project structure:
main_folder/
├─ MANIFEST.in
├─ setup.py
├─ mypgk/
│ ├─ __init__.py
│ ├─ main.py
│ ├─ files/
│ │ ├─ somewhat.csv
here is my setup.py
from setuptools import setup, find_packages
setup(
name='mypkg',
version='0.0.1',
packages=find_packages(exclude=('test*', 'testing*'))
)
MANIFEST.in
recursive-include mypkg *.csv
main.py:
import csv
config_file = os.path.join('mypkg', 'files', 'somewhat.csv')
with open(config_file, 'r') as config_file:
reader = csv.reader(config_file)
running this script in the same directory works, but when I use it on other directories, FileNotFound error is prompted, Have I missed something?
oddly when I type python setup.py sdist
it is confirmed in the distribution
copying MANIFEST.in -> mypkg-0.0.1
copying setup.py -> mypkg-0.0.1
copying mypkg\main.py -> mypkg-0.0.1\mypkg
copying mypkg\__init__.py -> mypkg-0.0.1\mypkg
copying mypkg.egg-info\PKG-INFO -> mypkg-0.0.1\mypkg.egg-info
copying mypkg.egg-info\SOURCES.txt -> mypkg-0.0.1\mypkg.egg-info
copying mypkg.egg-info\dependency_links.txt -> mypkg-0.0.1\mypkg.egg-info
copying mypkg.egg-info\top_level.txt -> mypkg-0.0.1\mypkg.egg-info
copying mypkg\files\somewhat.csv -> mypkg-0.0.1\mypkg\files
but going in the directory, I found no files folder