Pre-commit install-hooks does not work (SSLError)

Question:

I use conda Python environments. Whenever I try to run pre-commit install-hooks, I get the error

 Could not fetch URL https://pypi.org/simple/ruamel-yaml/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded w
ith url: /simple/ruamel-yaml/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

...

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

However, pip works just fine when I use it.

I already tried pre-commit clean, uninstalling pre-commit and reinstalling it (either with conda or pip), updating pip, switching off the VPN, and also any other solution I could find on Google. Nothing seems to work. Could you please help me?

The .pre-commit-config.yaml looks like this:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
    -   id: check-yaml
    -   id: check-added-large-files
-   repo: https://github.com/psf/black
    rev: stable
    hooks:
    - id: black
      language_version: python3.8
-   repo: https://github.com/pycqa/isort
    rev: 5.10.1
    hooks:
      - id: isort
        name: isort (python)

Asked By: karu

||

Answers:

The following helped me:

  • uninstall pre-commit (via pip/conda)
  • delete the pre-commit.exe (found by "where pre-commit"). That’s crucial; otherwise it still uses this exe even though pre-commit is installed in the conda env, and I still got the same error
  • install pre-commit via conda; pip doesn’t work because it still looks for the exe
Answered By: karu