PyInstaller failed.
Published: 2024-06-04 13:11:20

2024/6/4 

I run PyInstaller and failed by following error:
```
> pyinstaller -F .\main.py
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\kazto\work\MyProject\.venv\Scripts\pyinstaller.exe\__main__.py", line 8, in <module>
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\__main__.py", line 228, in _console_script_run
    run()
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\__main__.py", line 170, in run
    parser = generate_parser()
             ^^^^^^^^^^^^^^^^^
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\__main__.py", line 136, in generate_parser
    import PyInstaller.building.build_main
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\building\build_main.py", line 28, in <module>
    from PyInstaller.building.api import COLLECT, EXE, MERGE, PYZ
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\building\api.py", line 32, in <module>
    from PyInstaller.building.splash import Splash  # argument type validation in EXE
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\building\splash.py", line 23, in <module>
    from PyInstaller.depend import bindepend
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\depend\bindepend.py", line 25, in <module>
    from PyInstaller.depend import dylib, utils
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\depend\utils.py", line 31, in <module>
    from PyInstaller.lib.modulegraph import modulegraph
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 34, in <module>
    from altgraph.ObjectGraph import ObjectGraph
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\altgraph\__init__.py", line 144, in <module>
    __version__ = pkg_resources.require("altgraph")[0].version
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\pkg_resources\__init__.py", line 926, in require
    needed = self.resolve(parse_requirements(requirements))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\pkg_resources\__init__.py", line 787, in resolve
    dist = self._resolve_dist(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\pkg_resources\__init__.py", line 828, in _resolve_dist
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application
```

This error is caused by the following part:
```
  File "C:\Users\kazto\work\MyProject\.venv\Lib\site-packages\altgraph\__init__.py", line 144, in <module>
    __version__ = pkg_resources.require("altgraph")[0].version
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

`pkg_resources` is deprecated and `require()` doesn't work properly.

I worked around this problem by as follows:

1. Open `.venv\Lib\site-packages\pkg_resources\__init__.py`
2. rewrite \_\_version__ to `__version__ = "0.17.4"` (write installed altgraph's version)

This is a dirty workaround and should be fixed in the source code of the altgraph package.