Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with comtypes>=1.4.5 (ModuleNotFoundError: No module named 'comtypes.stream') #807

Closed
Avasam opened this issue Sep 21, 2024 · 3 comments · Fixed by #808
Closed
Labels
bug Something isn't working

Comments

@Avasam
Copy link

Avasam commented Sep 21, 2024

Describe the bug
With comtypes 1.4.5 or above, my PyInstaller frozen application fails with "ModuleNotFoundError: No module named 'comtypes.stream'", supposing it fails to include comtypes.stream.

  • Which hook/library isn't working? comtypes
  • Does the error get raised while building or when running? running

To Reproduce
A minimal example file:

import comtypes.client
# A DLL that can be loaded on your machine, in my case, a lib was calling:
comtypes.client.GetModule("qedit.dll") 

PyInstaller command:

pyinstaller test.py --onefile

Error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
  File "comtypes\client\_generate.py", line 128, in GetModule
  File "comtypes\client\_generate.py", line 232, in generate
  File "comtypes\client\_generate.py", line 280, in _get_known_namespaces
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'comtypes.stream'

Expected behavior
No error. Probably through a hook letting pyinstaller know that importing comtypes.client._generate has a chance of requiring comtypes.stream.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10.0.19045 Build 19045
  • Python Version: 3.11.6
  • Version of pyinstaller-hooks-contrib: 2024.8
  • Version of PyInstaller 6.10.0

Additional context
Adding --hidden-import comtypes.stream works. But comtypes is a big/popular enough library I think it's valuable to work with it "as-is".

@Avasam Avasam added the state:triage We're still figuring out how severe this issue is label Sep 21, 2024
@bwoodsend
Copy link
Member

Adding --hidden-import comtypes.stream to my build command didn't help.

Really? It works for me.

@Avasam
Copy link
Author

Avasam commented Sep 22, 2024

Really? It works for me.

Just tried again with the minimal repro and that works. Maybe I didn't pass it correctly when I tried in my project. I'll update my comment in the issue. The rest of the issue is still accurate.

@bwoodsend bwoodsend added bug Something isn't working and removed state:triage We're still figuring out how severe this issue is labels Sep 22, 2024
@bwoodsend
Copy link
Member

Might be worth adding all of these to hiddenimports.

@bwoodsend bwoodsend linked a pull request Sep 22, 2024 that will close this issue
github-actions bot pushed a commit to wxx9248/Pickle-Rush that referenced this issue Oct 16, 2024
…4.9 (#115)

Bumps
[pyinstaller-hooks-contrib](https://github.com/pyinstaller/pyinstaller-hooks-contrib)
from 2024.8 to 2024.9.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/releases">pyinstaller-hooks-contrib's
releases</a>.</em></p>
<blockquote>
<h2>v2024.9</h2>
<p>Please see the <a
href="https://www.github.com/pyinstaller/pyinstaller-hooks-contrib/tree/v2024.9/CHANGELOG.rst">changelog</a>
for more details</p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/CHANGELOG.rst">pyinstaller-hooks-contrib's
changelog</a>.</em></p>
<blockquote>
<h2>2024.9 (2024-10-15)</h2>
<p>New hooks</p>
<pre><code>
* Add a hook for comtypes to ensure compatibility with comtypes &gt;=
1.4.5.

(`[#807](pyinstaller/pyinstaller-hooks-contrib#807)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/807&gt;`_)
* Add analysis hook for ``slixmpp`` library
(`[#784](pyinstaller/pyinstaller-hooks-contrib#784)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/784&gt;`_)
* Add hook for ``capstone`` package.
(`[#787](pyinstaller/pyinstaller-hooks-contrib#787)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/787&gt;`_)
* Add hook for ``grapheme`` to collect its data files.
(`[#793](pyinstaller/pyinstaller-hooks-contrib#793)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/793&gt;`_)
* Add hook for ``onnxruntime`` to ensure that provider plugins are
collected.
(`[#817](pyinstaller/pyinstaller-hooks-contrib#817)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/817&gt;`_)
* Add hook for ``saml2`` package which has XSD files and hidden imports.
(`[#798](pyinstaller/pyinstaller-hooks-contrib#798)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/798&gt;`_)
* Add hook for ``setuptools_scm`` that collects metadata of
``setuptools``
  dist in order to avoid run-time warning about unknown/incompatible
``setuptools`` version.
(`[#805](pyinstaller/pyinstaller-hooks-contrib#805)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/805&gt;`_)
* Add hook for ``ultralytics`` package.
(`[#786](pyinstaller/pyinstaller-hooks-contrib#786)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/786&gt;`_)
* Add hook for ``xmlschema`` package which has XSD files.
(`[#797](pyinstaller/pyinstaller-hooks-contrib#797)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/797&gt;`_)
* Add hook for ``yapf_third_party`` (part of ``yapf``) to collect its
data files.
(`[#792](pyinstaller/pyinstaller-hooks-contrib#792)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/792&gt;`_)
* Add hooks for ``toga`` widget toolkit and its backends.
(`[#804](pyinstaller/pyinstaller-hooks-contrib#804)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/804&gt;`_)
* Add run-time hook for ``findlibs`` that overrides the
``findlibs.find``
function with custom implementation in order to ensure that the
top-level
  application directory is searched first. This prevents a system-wide
  copy of the library being found and loaded instead of the bundled copy
  when the system-wide copy happens to be available in one of fixed
locations that is scanned by the original implementation of
``findlibs.find``
(for example, Homebrew directory on macOS).
(`[#799](pyinstaller/pyinstaller-hooks-contrib#799)

&lt;https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/799&gt;`_)
<p>Updated hooks
</code></pre></p>
<ul>
<li>(Linux) Update <code>tensorflow</code> hook to suppress creation of
symbolic links
to the top-level application directory for the following shared
libraries
discovered during binary dependency analysis:
<code>libtensorflow_cc.so.2</code>,
<code>libtensorflow_framework.so.2</code>, and
<code>_pywrap_tensorflow_internal.so</code>.</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/5bcaf52e302d2adeaf4457c435ffa07f5b4b1f53"><code>5bcaf52</code></a>
Release v2024.9</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/5177ccbe491dc8d38ebddf01031ae192d11862e4"><code>5177ccb</code></a>
Scheduled weekly dependency update for week 41 (<a
href="https://redirect.github.com/pyinstaller/pyinstaller-hooks-contrib/issues/816">#816</a>)</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/bf3d57233f2af4823e438c491d908e293228a630"><code>bf3d572</code></a>
hooks: add hook for onnxruntime</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/f9f6e7e7a25b694fd033ca8c637907518b186dc9"><code>f9f6e7e</code></a>
ci: use python from actions/setup-python</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/85984500f39319103f363f19d67202cb44443204"><code>8598450</code></a>
hooks: update av hook for compatibility with av 13.1.0</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/374fb3100ab2d64472f64dcce964e56530573404"><code>374fb31</code></a>
Scheduled weekly dependency update for week 40, part 2 (<a
href="https://redirect.github.com/pyinstaller/pyinstaller-hooks-contrib/issues/815">#815</a>)</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/f33229b50dd6ad7699d1084495efc54fa1519d38"><code>f33229b</code></a>
Scheduled weekly dependency update for week 40 (<a
href="https://redirect.github.com/pyinstaller/pyinstaller-hooks-contrib/issues/813">#813</a>)</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/aad8cadb261208ca462a87159d0f8a498f0081cc"><code>aad8cad</code></a>
Scheduled weekly dependency update for week 39, part 2 (<a
href="https://redirect.github.com/pyinstaller/pyinstaller-hooks-contrib/issues/812">#812</a>)</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/463bf72b24ef83a6a4cf92fcc5a74018c6b29677"><code>463bf72</code></a>
Scheduled weekly dependency update for week 39 (<a
href="https://redirect.github.com/pyinstaller/pyinstaller-hooks-contrib/issues/811">#811</a>)</li>
<li><a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/commit/d53616c1e207903a7ce86bed1460dd3747f4a0ca"><code>d53616c</code></a>
Add hiddenimports for comtypes.client</li>
<li>Additional commits viewable in <a
href="https://github.com/pyinstaller/pyinstaller-hooks-contrib/compare/v2024.8...v2024.9">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pyinstaller-hooks-contrib&package-manager=pip&previous-version=2024.8&new-version=2024.9)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants