1 Востаннє редагувалося leofun01 (01.01.2024 21:52:38)

Тема: AttributeError: 'EntryPoints' object has no attribute 'get'

Після введення команди pre-commit run --all-files, вибиває помилку:

Format YAML files........................................................Failed
- hook id: yamlfmt
- exit code: 1
Executable `C:UsersFamily.cachepre-commitrepomga8empmpy_env-python3.12Scriptspython.EXE` not found

За вказаним шляхом python.exe наявний, але pre-commit його не бачить.
ОС Widnows 10
Python 3.12.1
Pre-commit 3.6.0

Налаштування прекомітта:

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: |
  (?x)^(
      ^.*grpc_stuff.*$|
      ^.*\/swagger.yaml$|
      ^.gitlab-ci.*.yml
  )$
repos:
  - repo: https://github.com/pycqa/flake8
    rev: 3.9.2
    hooks:
      - id: flake8
        args: [--max-line-length=120]
  - repo: https://github.com/psf/black
    rev: 22.8.0
    hooks:
      - id: black
  # - repo: https://github.com/PyCQA/pylint
  #   rev: v2.15.3
  #   hooks:
  #     - id: pylint
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.3.0
    hooks:
      - id: check-byte-order-marker
      - id: trailing-whitespace
        args: [--markdown-linebreak-ext=md]
      - id: end-of-file-fixer
      - id: debug-statements
  - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
    rev: 0.2.2
    hooks:
      - id: yamlfmt
        args: [--mapping, '2', --sequence, '4', --offset, '2', '-w', '120', --preserve-quotes, --implicit_start]

Як вийти з цієї ситуації?

2

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Одразу ж подумав про PATH, чат зі мною згідний. Також воно розказало про варіант із створенням віртуального середовища Python, який завжди доречний.

Copilot

The error message suggests that the pre-commit hook for formatting YAML files is not able to find the Python executable. This could be due to a variety of reasons, such as a misconfigured Python environment, incorrect PATH settings, or issues with the pre-commit configuration.

Here are a few steps you can take to troubleshoot this issue:

Verify that Python is correctly installed and accessible from the command line. You can do this by running python --version in your command prompt. This should print the Python version if it's correctly installed.

Check if the Python executable is in your system's PATH. You can do this by running echo %PATH% in your command prompt and looking for the path to the Python executable.

Try reinstalling the pre-commit hooks. You can do this by running pre-commit clean followed by pre-commit install.

If none of the above steps work, you might want to consider using a Python virtual environment. This can help isolate your Python environment and prevent conflicts between different versions of Python or Python packages. You can create a virtual environment by running python -m venv env, activate it by running .\env\Scripts\activate (on Windows), and then install pre-commit in the virtual environment by running pip install pre-commit.

If you're still having issues after trying these steps, please provide more information about your Python environment and pre-commit configuration for further assistance.

3

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Я новачок у цьому, сиджу і все сам вивчаю.
PATH вказаний корректно, але це стосується python.exe який лежить у корені програми python. Комміт я запускаю з env. Шлях python.exe у цьому разі відрізняється.
У першому разі:
C:\Users\Family\AppData\Local\Programs\Python\Python312\Scripts\
C:\Users\Family\AppData\Local\Programs\Python\Python312\
вони корректні, а от у другому разі шлях буде наступним:
C:\Users\Family\.cache\pre-commit\repomga8empm\py_env-python3.12\Scripts\python.EXE
І він теж корректний, але чомусь вибиває помилку.

4

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Wlad написав:

вибиває помилку:

Executable `C:UsersFamily.cachepre-commitrepomga8empmpy_env-python3.12Scriptspython.EXE` not found

Цей рядок вказує на не дійсний шлях для старту python.exe. Слеш має бути Linux'ний ('/'), а не DOS'ний ('\').

5

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Неясно чи дійсно було активовано віртуальне середовище, чи ні. І яким чином встановлювалося pre-commit, до чи після активації. Це все має значення.
https://replace.org.ua/uploads/images/9801/0678e468e38fa2e97482eb24f111c054.png

6

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Видалив віртуальне середовище.
Повторно створив, так як вказано в інстуркії, але всеодно видає помилку шляху. Мене от що бентежить, помилка вказана Executable `C:UsersFamily.cachepre-commitrepomga8empmpy_env-python3.12Scriptspython.EXE` not found, відсутній слеш ('/'), чому так? Можливо потрібно вказати правильний шлях просто додавши слеш, але як?
В змінних середовища у розділі PATH я вказав шлях зі слешем ('/'), але всеодно помилка.

7

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Неясно чи було видалено оригінальний pre-commit і встановлено новий вже після створення і активації віртуального середовища.

8

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Деактивував, видалив папку env.
Активував новий, інсталював по інструкції.

9

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Це знущання - давати повний текст помилки лише у вигляді скріншоту. Більше так не робіть, бо треба
тайпати самостійно, не кожен захоче вам наступного разу допомогти. З іншого боку, ви ж не показували досі всю інформацію в тексті і лише на скріншоті видно

eps = importlib_metadata.entry_points().get(self.namespace, ()) 
AttributeError: 'EntryPoints' object has no attribute 'get'

Я б запропонував копіювати весь текст помилки повністю, а не лише той шматок, який вважаєте найголовнішим. І додатково чіпляти скріншот (котрий ви не спромоглися причепити як малюнок, натомість причепили як url, але вже ок).

Дивлячись на процитований мною текст помилки вище, я б сильно радив даунґрейднути версію Python з 3.12 до хоча б 3.11 - воно в останній версії поки що сильно глюкаве, мені теж траплялося декілька схожих помилок і лише повернення до попередньої версії дозволило рухатися далі.

10

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Запустив з 3.11.6 все те ж саме
Встановив Unbutu, там все ок.

11

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

Теж використовую Ubuntu і тут все ок.

12

Re: AttributeError: 'EntryPoints' object has no attribute 'get'

'EntryPoints' object has no attribute 'get' проблему вирішив. Ця помилка трапляється через проблеми з версіями бібліотеки flake8 та importlib_metadata.
А от зі шляхом досі нічого не виходить. Хоча й на ubuntu перейшов, але хочу виправити цю помилку.