[PYTHON] Install the data files with setup.py

Directory structure

Installation source

.../ ├──setup.py └──my_module   └──data     ├──a.dat     ├──b.dat     ├──...

Place of installation

.../ ├──site-packages └──my_module   └──data     ├──a.dat     ├──b.dat     ├──...

code

setup.py


import sys
import site
import glob
import os.path
from distutils.core import setup

# site-Get the path of the package directory
#* At the top of the list"C:\Python34"Seems to contain, so the last is site-Process it assuming that it is a package (Please let me know if there is a good way because it seems not certain)
sitedir = site.getsitepackages()[-1]
#Installation directory
installdir = os.path.join(sitedir, 'my_module')

#Get the root directory of the module you are installing from
# ※setup.Get with relative path from py
mydir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'my_module')
#Get a list of data files
datafiles = glob.glob(os.path.join(mydir, 'data', '*.dat'))

setup(
      ...,
      packages=['my_module'],
      #Pass the installation directory and a list of files to install as tuples
      data_files=[(os.path.join(installdir, 'data'), datafiles)]
)

reference

Tutorial on Packaging and Distributing Projects — Python Packaging User Guide documentation python - setup.py not installing data files - Stack Overflow

Recommended Posts

Install the data files with setup.py
Install the Python plugin with Netbeans 8.0.2
Search for files with the specified extension
Install by specifying the version with pip
Download files on the web with Python
I can't install the package with pip.
[Python] Get the files in a folder with Python
I tried to save the data with discord
Get data files from elsewhere during pip install
Display the image after Data Augmentation with Pytorch
Data analysis with python 2
Upload files with Django
Extract the table of image files with OneDrive & Python
Reading data with TensorFlow
Error with pip install
Install Voluptuous with Python 2.5
Data visualization with pandas
Extract files from EC2 storage with the scp command
Get comments and subscribers with the YouTube Data API
Data manipulation with Pandas!
Install the latest stable Python with pyenv (both 2 and 3)
Install the pip command
Install torch-scatter with PyTorch 1.7
Shuffle data with pandas
Install python with pyenv
Install Ubuntu 20.04 with GUI and prepare the development environment
Data Augmentation with openCV
Install the latest Python from pyenv installed with homebrew
Normarize data with Scipy
Data analysis with Python
Extract the band information of raster data with python
Install scikit.learn with pip
Install The Virtual Brain
LOAD DATA with PyMysql
Try scraping the data of COVID-19 in Tokyo with Python
A network diagram was created with the data of COVID-19.
Getting Started with Drawing with matplotlib: Creating Diagrams from Data Files
Can't find the package you installed with pip install --user?
Solve the spiral book (algorithm and data structure) with python!
Process the files in the folder in order with a shell script
The story of rubyist struggling with python :: Dict data with pycall
[Homology] Count the number of holes in data with Python
[Introduction to Python] How to get data with the listdir function
Try to extract the features of the sensor data with CNN
Embed audio data with Jupyter
Graph Excel data with matplotlib (1)
Artificial data generation with numpy
Install Python environment with Anaconda
Install Keras (used with Anaconda)
Insert the debugger with nose
Extract Twitter data with CSV
Kill the process with sudo kill -9
Specify version with conda install
Gzip the data by streaming
Install the JDK on Linux
Sorting image files with Python (2)
Clustering ID-POS data with LDA
Sort huge files with python
Sorting image files with Python (3)
Learn new data with PaintsChainer
Install external libraries with Python