Skip to content

Executing zipapp with Python 3.10 or earlier fails on importing 'tomli' #1142

@sgryjp

Description

@sgryjp

Describe the bug

Executing the zipapp of pipx with Python 3.10 or earlier fails on trying to import tomli which is not included in pipx.pyz.

How to reproduce

Executing pipx.pyz of version 1.3.2 using Python 3.10 or earlier will always reproduce the error. Below is an example output:

mac:~/Downloads% python3.11 pipx.pyz --version
1.3.3
mac:~/Downloads% python3.10 pipx.pyz --version
Traceback (most recent call last):
  File "/Users/sgryjp/Downloads/pipx.pyz/_bootstrap/__init__.py", line 76, in import_string
  File "/Users/sgryjp/.shiv/pipx.pyz_0fe43a768b3b979cecbbd4b3678299380e71ea146670c0f28fd6199751c78f96/site-packages/pipx/main.py", line 23, in <module>
    from pipx import commands, constants
  File "/Users/sgryjp/.shiv/pipx.pyz_0fe43a768b3b979cecbbd4b3678299380e71ea146670c0f28fd6199751c78f96/site-packages/pipx/commands/__init__.py", line 7, in <module>
    from pipx.commands.run import run
  File "/Users/sgryjp/.shiv/pipx.pyz_0fe43a768b3b979cecbbd4b3678299380e71ea146670c0f28fd6199751c78f96/site-packages/pipx/commands/run.py", line 30, in <module>
    import tomli as tomllib
ModuleNotFoundError: No module named 'tomli'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sgryjp/Downloads/pipx.pyz/_bootstrap/__init__.py", line 84, in import_string
AttributeError: module 'pipx' has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/sgryjp/Downloads/pipx.pyz/__main__.py", line 3, in <module>
  File "/Users/sgryjp/Downloads/pipx.pyz/_bootstrap/__init__.py", line 253, in bootstrap
  File "/Users/sgryjp/Downloads/pipx.pyz/_bootstrap/__init__.py", line 81, in import_string
  File "/Users/sgryjp/Downloads/pipx.pyz/_bootstrap/__init__.py", line 87, in import_string
ImportError: module 'pipx' has no attribute 'main'

Expected behavior

pipx.pyz can be executed without an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingzipapp

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions