Repository: pydantic/pydantic

Issue:
Pyinstaller is choking with pydantic
### Checks

* [X] I added a descriptive title to this issue
* [X] I have searched (google, github) for similar issues and couldn't find anything
* [X] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->

# Bug

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.8.1
            pydantic compiled: True
                 install path: /root/.cache/pypoetry/virtualenvs/featuredproductsswitch-fvfue_C3-py3.8/lib/python3.8/site-packages/pydantic
               python version: 3.8.7 (default, Mar 22 2021, 22:55:25)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
                     platform: Linux-3.10.0-1127.el7.x86_64-x86_64-with-glibc2.2.5
     optional deps. installed: ['dotenv', 'typing-extensions']
```

<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->

<!-- Where possible please include a self-contained code snippet describing your bug: -->

## To Reproduce

1. Given a very simple script,

config.py
```py
from pydantic import BaseSettings


class Settings(BaseSettings):
    A_SETTING: str

settings = Settings()
```

test_pydantic.py
```py
from config import settings

if __name__ == "__main__":
    print(settings.A_SETTING)
```

2. Run `pyinstaller  -p [PATH_TO_YOUR_PROJECT'S SITE_PACKAGES]/site-packages test_pydantic.py`

## Expected output

Pyinstaller successfully packages script 🎉

## Actual output

We get an error: `AttributeError: Module 'pydantic' has no attribute '__version__'`

```sh
....
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/utils/hooks/__init__.py", line 531, in is_module_satisfies
    version = get_module_attribute(module_name, version_attr)
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/utils/hooks/__init__.py", line 328, in get_module_attribute
    raise AttributeError(
AttributeError: Module 'pydantic' has no attribute '__version__'
```

<details>
<summary>complete stacktrace when I ran pyinstaller</summary>

```sh
50 INFO: PyInstaller: 4.2
51 INFO: Python: 3.8.7
51 INFO: Platform: Linux-3.10.0-1127.el7.x86_64-x86_64-with-glibc2.2.5
54 INFO: wrote /home/vagrant/script/test_pydantic.spec
57 INFO: UPX is not available.
61 INFO: Extending PYTHONPATH with paths
['/home/vagrant/script',
 '/root/.cache/pypoetry/virtualenvs/featuredproductsswitch-fvfue_C3-py3.8/lib/python3.8/site-packages',
 '/home/vagrant/script']
66 INFO: checking Analysis
66 INFO: Building Analysis because Analysis-00.toc is non existent
66 INFO: Initializing module dependency graph...
69 INFO: Caching module graph hooks...
75 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
79 INFO: Analyzing base_library.zip ...
3190 INFO: Processing pre-find module path hook distutils from '/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
3191 INFO: distutils: retargeting to non-venv dir '/usr/local/python3.8/lib/python3.8'
6098 INFO: Caching module dependency graph...
6258 INFO: running Analysis Analysis-00.toc
6285 INFO: Analyzing /home/vagrant/script/test_pydantic.py
6343 INFO: Processing module hooks...
6343 INFO: Loading module hook 'hook-pydantic.py' from '/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
Traceback (most recent call last):
  File "/root/.local/bin/pyinstaller", line 8, in <module>
    sys.exit(run())
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 672, in build
    exec(code, spec_namespace)
  File "/home/vagrant/script/test_pydantic.spec", line 6, in <module>
    a = Analysis(['test_pydantic.py'],
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 242, in __init__
    self.__postinit__()
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/building/datastruct.py", line 160, in __postinit__
    self.assemble()
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 420, in assemble
    self.graph.process_post_graph_hooks()
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/depend/analysis.py", line 367, in process_post_graph_hooks
    module_hook.post_graph()
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/depend/imphook.py", line 447, in post_graph
    self._load_hook_module()
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/depend/imphook.py", line 408, in _load_hook_module
    self._hook_module = importlib_load_source(
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/compat.py", line 598, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 962, in load_module
  File "<frozen importlib._bootstrap_external>", line 787, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pydantic.py", line 35, in <module>
    if not is_module_satisfies('pydantic >= 1.4'):
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/utils/hooks/__init__.py", line 531, in is_module_satisfies
    version = get_module_attribute(module_name, version_attr)
  File "/root/.local/pipx/venvs/pyinstaller/lib/python3.8/site-packages/PyInstaller/utils/hooks/__init__.py", line 328, in get_module_attribute
    raise AttributeError(
AttributeError: Module 'pydantic' has no attribute '__version__'
```
</details>


Discussion:

Resolving patch:
diff --git a/pydantic/__init__.py b/pydantic/__init__.py
--- a/pydantic/__init__.py
+++ b/pydantic/__init__.py
@@ -14,6 +14,8 @@
 from .types import *
 from .version import VERSION
 
+__version__ = VERSION
+
 # WARNING __all__ from .errors is not included here, it will be removed as an export here in v2
 # please use "from pydantic.errors import ..." instead
 __all__ = [


Test patch:
diff --git a/tests/test_version.py b/tests/test_version.py
new file mode 100644
--- /dev/null
+++ b/tests/test_version.py
@@ -0,0 +1,9 @@
+import pydantic
+
+
+def test_version_attribute_is_present():
+    assert hasattr(pydantic, '__version__')
+
+
+def test_version_attribute_is_a_string():
+    assert isinstance(pydantic.__version__, str)