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

AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? #1368

Open
aorumbayev opened this issue Apr 24, 2024 · 3 comments

Comments

@aorumbayev
Copy link

aorumbayev commented Apr 24, 2024

Describe the bug

The following repo was specifically created to outline a reproducible environment with the bug https://github.com/aorumbayev/pipx_bug.

I am not sure of the root cause but it is something to do with the way pipx uses shared venv and running pipx installed executable python modules that have copier package as transitive dependency installed for target py >=3.12 while pipx itself is installed with py <3.12.

I also opened this issue on copier repo copier where copier maintainers forwarded me to also open an issue on plumbum transitive dependency that they rely on (and which throws the error) -> available here tomerfiliba/plumbum#678. Yet, still opening the issue on pipx repo as well given that copier maintainers also suspect that something may be wrong with the way shared venv is reused by pipx. Based on logs pipx is somehow able to access packages across multiple venvs. The issue is easily reproduced on github codespaces or github actions (use ubuntu-latest workers). If you have pipx installed locally on your machine and it was installed using 3.12 as a base python - everything works just fine (because the shared venv on pipx side is also using 3.12 in that case).

Logs

Traceback (most recent call last):
  File "/usr/local/py-utils/bin/pipx-bug-cli", line 5, in <module>
    from pipx_bug.cli import hello
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/pipx_bug/cli.py", line 2, in <module>
    from copier.main import Worker
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/copier/__init__.py", line 6, in <module>
    from .main import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/copier/main.py", line 33, in <module>
    from plumbum.cli.terminal import ask
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/plumbum/cli/__init__.py", line 1, in <module>
    from .application import Application
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/plumbum/cli/application.py", line 9, in <module>
    from plumbum.cli.i18n import get_translation_for
  File "/usr/local/py-utils/venvs/pipx-bug/lib/python3.12/site-packages/plumbum/cli/i18n.py", line 28, in <module>
    import pkg_resources
  File "/usr/local/py-utils/shared/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2191, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

How to reproduce

Refer to readme on https://github.com/aorumbayev/pipx_bug

Expected behavior

Executing packages via pipx on >=3.12 should defer to 3.12 based shared venv

@henryiii
Copy link
Contributor

henryiii commented Apr 28, 2024

The problem is:

Python 3.12.2 (main, Apr 23 2024, 13:31:25) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/home/codespace/.pyenv/versions/3.12.2/lib/python312.zip', '/home/codespace/.pyenv/versions/3.12.2/lib/python3.12', '/home/codespace/.pyenv/versions/3.12.2/lib/python3.12/lib-dynload', '/usr/local/py-utils/venvs/algokit/lib/python3.12/site-packages', '/usr/local/py-utils/shared/lib/python3.10/site-packages']

The 3.10 site-packages is sneaking in there, and I don't see how. It's only in the pipx venv Python, but pyvenv.cfg seems fine, etc. More info at tomerfiliba/plumbum#678.

@aorumbayev
Copy link
Author

Any updates on the issue so far?

Also thanks for attempts to fix it on plumbum side @henryiii , let me know if you need help testing out that draft pr in codespaces 👍

@atmask
Copy link

atmask commented May 29, 2024

Same issue here. Install v1.5.0 via brew and getting this when trying to pipx install poetry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants