question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: No module named 'pkg_resources' when installing environment

See original GitHub issue

Hi.

I’m getting the error below both on Python 3.10.0 and 3.9.7, only on this mirrors-prettier repo.

[INFO] Installing environment for https://github.com/pre-commit/mirrors-prettier.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/Users/aa/.pyenv/versions/3.10.0/bin/python3', '/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python', '-mnodeenv', '--prebuilt', '--clean-src', '/Users/aa/.cache/pre-commit/repoj2j9vjbi/node_env-system', '-n', 'system')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    Traceback (most recent call last):
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 48, in <module>
        exit(main())
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 32, in main
        runpy.run_module(args.m, run_name='__main__', alter_sys=True)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 209, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/nodeenv-1.6.0-py2.py3-none-any.whl/nodeenv.py", line 48, in <module>
    ModuleNotFoundError: No module named 'pkg_resources'

Check the log at /Users/aa/.cache/pre-commit/pre-commit.log
make: *** [.cache/make/pre-commit] Error 3
  1. Other pre-commit repos work fine.
  2. None of them are NodeJS repos as far as I know.
  3. It’s happening on a freshly installed computer; it works on my old one.
  4. I wonder if it has something to do with my NodeJS installation, but I’m not sure and I don’t know how to debug it.
  5. Let me know if I have to post more information about my system.

Below is what I tried so far, to no success. I’d appreciate any lead, hint or help.

Thanks!


I tried reinstalling setuptools with both python executables:

❯ /Users/aa/.pyenv/versions/3.10.0/bin/python3 -m pip install -U pip setuptools
Requirement already satisfied: pip in /Users/aa/.pyenv/versions/3.10.0/lib/python3.10/site-packages (21.3.1)
Requirement already satisfied: setuptools in /Users/aa/.pyenv/versions/3.10.0/lib/python3.10/site-packages (58.5.3)
❯ /Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python -m ensurepip
Looking in links: /var/folders/t_/w0p3tjc95tjd0vld929q66rh0000gn/T/tmpcc0nkqh6
Requirement already satisfied: setuptools in /Users/aa/.pyenv/versions/3.10.0/lib/python3.10/site-packages (58.5.3)
Requirement already satisfied: pip in /Users/aa/.pyenv/versions/3.10.0/lib/python3.10/site-packages (21.3.1)
❯ /Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python -m pip install -U pip setuptools
Traceback (most recent call last):
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 48, in <module>
    exit(main())
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 32, in main
    runpy.run_module(args.m, run_name='__main__', alter_sys=True)
  File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 205, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 140, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named pip

Here are the contents of /Users/aa/.cache/pre-commit/pre-commit.log:

/Users/aa/.cache/pre-commit/pre-commit.log

version information

pre-commit version: 2.15.0
sys.version:
    3.10.0 (default, Oct 31 2021, 00:48:30) [Clang 12.0.5 (clang-1205.0.22.11)]
sys.executable: /Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/Users/aa/.pyenv/versions/3.10.0/bin/python3', '/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python', '-mnodeenv', '--prebuilt', '--clean-src', '/Users/aa/.cache/pre-commit/repoj2j9vjbi/node_env-system', '-n', 'system')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    Traceback (most recent call last):
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 48, in <module>
        exit(main())
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 32, in main
        runpy.run_module(args.m, run_name='__main__', alter_sys=True)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 209, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/nodeenv-1.6.0-py2.py3-none-any.whl/nodeenv.py", line 48, in <module>
    ModuleNotFoundError: No module named 'pkg_resources'
    
Traceback (most recent call last):
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/main.py", line 396, in main
    return run(args.config, store, args)
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/commands/run.py", line 417, in run
    install_hook_envs(to_install, store)
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/repository.py", line 224, in install_hook_envs
    _hook_install(hook)
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/repository.py", line 82, in _hook_install
    lang.install_environment(
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/languages/node.py", line 97, in install_environment
    cmd_output_b(*cmd)
  File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/pre_commit-2.15.0-py2.py3-none-any.whl/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/Users/aa/.pyenv/versions/3.10.0/bin/python3', '/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python', '-mnodeenv', '--prebuilt', '--clean-src', '/Users/aa/.cache/pre-commit/repoj2j9vjbi/node_env-system', '-n', 'system')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    Traceback (most recent call last):
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 48, in <module>
        exit(main())
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/python", line 32, in main
        runpy.run_module(args.m, run_name='__main__', alter_sys=True)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 209, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Users/aa/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/Users/aa/.cache/pre-commit-zipapp/veR-6hXwmzX2ScBOxSDU3KDEapmTGSUiy_rUDxSkW24/wheels/nodeenv-1.6.0-py2.py3-none-any.whl/nodeenv.py", line 48, in <module>
    ModuleNotFoundError: No module named 'pkg_resources'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
asottilecommented, Nov 6, 2021

no so the reason it would need to have an install_requires=['setuptools'] there is so that the setuptools wheel also gets pulled in when building the zipapp (if you, for instance, add a setuptools-....whl into that wheel directory it’ll start working)

the patch you suggested above is not correct, the zipapp intentionally isolates itself from the system

1reaction
asottilecommented, Nov 6, 2021

it looks like you’re using the zipapp and that nodeenv is missing a dependency on setuptools (where pkg_resources comes from) – probably worth a PR here

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named pkg_resources - python - Stack Overflow
This error message is caused by a missing/broken Python setuptools package. Per Matt M.'s comment and setuptools issue #581, the bootstrap script referred...
Read more >
No module named 'pkg_resources' in Python | bobbyhadz
The Python "No module named 'pkg_resources'" occurs when setuptools is not installed in our Python environment. To solve the error, ...
Read more >
Fix for 'ImportError: No module named pkg_resources' error
You will see this error when you try to install a PIP package. This error message means Python setuptools is missing or broken....
Read more >
The error was: ImportError: No module named pkg_resources
The fix for this error is to not activate the virtualenv after the ansble-bootstrap step. We've updated the installation page to include this, ......
Read more >
No module named 'pkg_resources', setuptools is installed : r ...
Can't run pip: ModuleNotFoundError: No module named 'pkg_resources', setuptools is installed. Edit: Problem solved The packages python3 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found