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

No module named 'yaml' when run by pre-commit in VSCode git commit #702

Open
szinn opened this issue Nov 28, 2024 · 4 comments
Open

No module named 'yaml' when run by pre-commit in VSCode git commit #702

szinn opened this issue Nov 28, 2024 · 4 comments

Comments

@szinn
Copy link

szinn commented Nov 28, 2024

pre-commit works fine when executed from cli on Mac.

However, when run via a commit within VSCode, getting

  File "/Users/scotte/.cache/pre-commit/repoy1fgff94/py_env-python3.12/bin/yamllint", line 5, in <module>
    from yamllint.cli import run
  File "/Users/scotte/.cache/pre-commit/repoy1fgff94/py_env-python3.12/lib/python3.12/site-packages/yamllint/cli.py", line 22, in <module>
    from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION, linter
  File "/Users/scotte/.cache/pre-commit/repoy1fgff94/py_env-python3.12/lib/python3.12/site-packages/yamllint/linter.py", line 19, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'```

PyYAML is installed on the system 

Thoughts?
@andrewimeson
Copy link
Contributor

This issue would be better looked at from the pre-commit side. You could try deleting and recreating the pre-commit environment. Take a look at #674

@szinn
Copy link
Author

szinn commented Nov 28, 2024

I've done that with no change. Tried also adding PyYAML as an additional dependency with no luck. Will check the pre-commit side. Likely there's some weird python version mismatch going on

@szinn
Copy link
Author

szinn commented Nov 28, 2024

Running pip3 list in the .cache/pre-commit repo for yamllint does not show PyYAML as being installed. If I use that pip to install PyYAML, then the issue is resolved. It appears that the dependency for PyYAML isn't declared perhaps?

@andrewimeson
Copy link
Contributor

It works for me with the following .pre-commit-config.yaml

---
repos:
  - repo: https://github.com/adrienverge/yamllint.git
    rev: v1.35.1
    hooks:
      - id: yamllint
        args: [--strict]
$ python3.12 -m venv .venv
$ source .venv/bin/activate
$ pip freeze  # No PyYAML present
$ pip install pre-commit
$ pre-commit run --all-files
yamllint.................................................................Passed

What version of yamllint are you targeting?

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

2 participants