Repository: pyinstaller/pyinstaller

Issue:
pkg_resources.DistributionNotFound: The 'django-babel' distribution was not found and is required by the application
I'm generating a django project exe and in it's setting a package of "django_babel" and sucessfully able to generate exe but when executing the exe i'm getting following error.

Perhaps I have included the "import djang_babel" in manage.py but error remain same.
I'm using latest Pyinstaller and Django2.0.


(django1point8Env) C:\pythonWebCode\django-custom-user-model\exe>dist\django-custom-user-model\django-custom-user-model.exe runsslserver
> c:\pythonwebcode\django-custom-user-model\exe\manage.py(14)<module>()
(Pdb) c
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "c:\pythonwebcode\django1point8env\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\django_babel\__init__.py", line 4, in <module>
  File "lib\site-packages\pkg_resources\__init__.py", line 472, in get_distribution
  File "lib\site-packages\pkg_resources\__init__.py", line 344, in get_provider
  File "lib\site-packages\pkg_resources\__init__.py", line 892, in require
  File "lib\site-packages\pkg_resources\__init__.py", line 778, in resolve
pkg_resources.DistributionNotFound: The 'django-babel' distribution was not found and is required by the application
[17608] Failed to execute script manage


Discussion:
I tried just for simple test.py as follows and not a django project and still it gives same error.

test.py
==============

import importlib
import django_babel
import datetime

if __name__ == '__main__':

	print("Hello dear friend, how are you")
	today = datetime.date.today()  
	print(today)


generated exe as follows
==================
pyinstaller test.py

executed exe and getting the same error
========================

(django1point8Env) C:\pythonWebCode\test>dist\test\test.exe
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import django_babel
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "c:\pythonwebcode\django1point8env\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\django_babel\__init__.py", line 4, in <module>
  File "lib\site-packages\pkg_resources\__init__.py", line 472, in get_distribution
  File "lib\site-packages\pkg_resources\__init__.py", line 344, in get_provider
  File "lib\site-packages\pkg_resources\__init__.py", line 892, in require
  File "lib\site-packages\pkg_resources\__init__.py", line 778, in resolve
pkg_resources.DistributionNotFound: The 'django-babel' distribution was not found and is required by the application
[17452] Failed to execute script test
I assume a hook is needed for `django-babel` to include the meta-data.
We would appreciate if you'd submit a pull-request for a hook for this. See [this section of the manual](https://pyinstaller.readthedocs.org/en/latest/hooks.html) for more information about how to implement hooks and otehr hooks for how to include the meta-data. See our Development Guide on [how to create pull-requests for PyInstaller](https://pyinstaller.readthedocs.io/en/stable/development/pull-requests.html). Thanks.

Resolving patch:
diff --git a/PyInstaller/hooks/hook-django_babel.py b/PyInstaller/hooks/hook-django_babel.py
new file mode 100644
--- /dev/null
+++ b/PyInstaller/hooks/hook-django_babel.py
@@ -0,0 +1,15 @@
+#-----------------------------------------------------------------------------
+# Copyright (c) 2005-2019, PyInstaller Development Team.
+#
+# Distributed under the terms of the GNU General Public License with exception
+# for distributing bootloader.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+# Tested with django-babel v0.6.2.
+# Hook for https://github.com/python-babel/django-babel
+
+from PyInstaller.utils.hooks import copy_metadata
+datas = copy_metadata('django-babel')
+


Test patch: