1

How can I include files that are not written in python to the packaging? Or to make it more concrete: Assuming I have the following package structure, how do I include all the files of the templates directory?

- projectname
  - __init__.py
  - classfile.py
  - templates
    - file1.prototxt
    - file2.caffemodel

I have the following setup.py

from distutils.core import setup
setup(
  name = 'projectname',    
  packages = ['projectname'], 
  version = '0.1',      
  license='MIT',        
  description = 'my description',  
  author = 'FULL NAME',                
  author_email = 'example@gmail.com',     
  url = 'https://github.com/repo',   
  download_url = 'https://github.com/repo/.../v_01.tar.gz',
  keywords = ['keywords'],  
  install_requires=[      
          'opencv-python',
          'numpy'
      ],
  classifiers=[
    'Development Status :: 3 - Alpha',      
    'Intended Audience :: Developers',      
    'Topic :: Software Development :: Build Tools',
    'License :: OSI Approved :: MIT License',  
    'Programming Language :: Python :: 3',     
  ],
)

As I read somewhere on stackoverflow, I tried adding the following to the setup.py file but it didn't make a difference.

package_data = {
      'templates': ['*'],
  }
phd
  • 82,685
  • 13
  • 120
  • 165
questioning
  • 245
  • 1
  • 4
  • 18

2 Answers2

2

Preamble. The word "package" is heavily overloaded. I'll use the word meaning "importable package", i.e. an directory with __init__.py.

I see two problems with your code. First, you use distutils which is an obsolete outdated package. It will be removed from Python. You should switched to setuptools long ago. So replace the line

from distutils.core import setup

with

from setuptools import setup

The 2nd problem is in

package_data = {
    'templates': ['*'],
}

The keys in the dictionary are packages, not directory names. Your templates is not a package (no __init__.py) but a data directory. So the way to include it is

package_data = {
    'projectname': ['templates/*'],
}
phd
  • 82,685
  • 13
  • 120
  • 165
0

Potential duplicate of this question

include_package_data=True
Pythoner
  • 460
  • 6
  • 23
  • Adding `include_package_data=True` did not solve the issue :/ – questioning Nov 09 '21 at 21:16
  • Did you check the link that I cited, and the link that they cited? They have more details about the solution, its not just that single line :) – Pythoner Nov 09 '21 at 21:20
  • 2
    @Pythoner "*Did you check the link that I cited, and the link that they cited? They have more details about the solution…*" In that case your answer is not an answer. An answer must be self-contained. – phd Nov 09 '21 at 21:28
  • @phd "An answer must be self-contained" -- I am happy to copy the contents of both links and paste them here, but referencing the solution of the duplicate question seemed more efficient. – Pythoner Nov 09 '21 at 21:38