marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
7.21k stars 251 forks source link

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

Closed simonw closed 4 weeks ago

simonw commented 4 weeks ago

Describe the bug

I got this error after trying to install a package using the Marimo tool for installing packages. Related but not the same as:

Environment

{
  "marimo": "0.9.1",
  "OS": "Darwin",
  "OS Version": "24.0.0",
  "Processor": "arm",
  "Python Version": "3.12.0",
  "Binaries": {
    "Browser": "129.0.6668.90",
    "Node": "v22.4.1"
  },
  "Dependencies": {
    "click": "8.1.7",
    "importlib-resources": "missing",
    "jedi": "0.19.1",
    "markdown": "3.7",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.11.2",
    "ruff": "0.6.9",
    "starlette": "0.39.2",
    "tomlkit": "0.13.2",
    "typing-extensions": "missing",
    "uvicorn": "0.31.0",
    "websockets": "12.0"
  },
  "Optional Dependencies": {}
}

Code to reproduce

cd /tmp
mkdir marimo-venv
cd marimo-venv
python -m venv venv
source venv/bin/activate
pip install marimo
marimo new

Then:

import llm

And ask it to install that package.

simonw commented 4 weeks ago

Here's the full traceback:

ERROR: Exception:
Traceback (most recent call last):
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 326, in run
    session = self.get_default_session(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 98, in get_default_session
    self._session = self.enter_context(self._build_session(options))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
              ^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/network/session.py", line 343, in __init__
    self.headers["User-Agent"] = user_agent()
                                 ^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution
    return next(matches, None)
           ^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr>
    matches = (
              ^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/base.py", line 612, in iter_all_distributions
    for dist in self._iter_distributions():
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions
    for dist in finder.find_eggs(location):
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs
    yield from self._find_eggs_in_dir(location)
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
    from pip._vendor.pkg_resources import find_distributions
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
Traceback (most recent call last):
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/__pip-runner__.py", line 50, in <module>
    runpy.run_module("pip", run_name="__main__", alter_sys=True)
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/__main__.py", line 31, in <module>
    sys.exit(_main())
             ^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/main.py", line 70, in main
    return command.main(cmd_args)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 101, in main
    return self._main(args)
           ^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
    self.handle_pip_version_check(options)
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 179, in handle_pip_version_check
    session = self._build_session(
              ^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
              ^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/network/session.py", line 343, in __init__
    self.headers["User-Agent"] = user_agent()
                                 ^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution
    return next(matches, None)
           ^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr>
    matches = (
              ^
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/base.py", line 612, in iter_all_distributions
    for dist in self._iter_distributions():
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions
    for dist in finder.find_eggs(location):
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs
    yield from self._find_eggs_in_dir(location)
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
    from pip._vendor.pkg_resources import find_distributions
  File "/private/tmp/marimo-venv/venv/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
akshayka commented 4 weeks ago

I googled AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? and found a lot of hits.

So it seems like the version of pip that is being used is incompatible with Python 3.12.

Why that would happen, I am currently unsure.

I noticed you marimo env lists Python 3.12, but your venv appears to be using Python 3.10, which is perplexing but could explain the issue.

Is it at all possible that marimo is installed globally? Does which marimo return something inside the venv or outside it?

simonw commented 4 weeks ago

I'm definitely suffering from https://xkcd.com/1987/ - I've lost track of which Python environment and which Marimo installations I have lying around I'm afraid.

I think you're right, the root cause here is definitely that I somehow had a Python 3.12 running against a 3.10 virtual environment. No idea at all how that happened though!

akshayka commented 4 weeks ago

Looking forward to the day when uv is totally feature complete and universally adopted and never have to think about virtual environments again 😅 One can dream ...!