3

I have an Anaconda environment in my current project. I have been trying to configure my pre-commit hooks, however I keep running unto this error:

enter image description here

So, the first time round when I got this error, I did some research and saw that ruamel.yaml needs to be installed. So, I did a pip install of ruamel.yaml and I did conform that the latest version is installed:

enter image description here

However, the error still persists. The most relevant posts I saw on the topic don't really seem to solve the problem:

https://github.com/pre-commit/pre-commit-hooks/issues/353

How can I get rid of this error?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
UGuntupalli
  • 769
  • 1
  • 9
  • 22
  • your ssl module is broken, pip can't function with a broken ssl module -- I can't reproduce myself as I have a working ssl module (try reinstalling things!) – anthony sottile Aug 15 '21 at 20:16
  • if the ssl module is broken, I should be unable to install any new package, but that is not the case here - is it ? – UGuntupalli Aug 16 '21 at 17:35
  • it's perhaps only broken in virtualenvs? – anthony sottile Aug 16 '21 at 18:42
  • 1
    There's something funny about pre-commit and ssl on some installations (Windows only? Windows with specific policies in place? I don't know). I can use pip without errors in my virtual environments, everything works normally, except for pre-commit, which generates OP's error for me as well. So ssl is not generally broken, it's just broken in a very narrow context that I unfortunately still don't understand well enough to fix cleanly. (My answer below is a functional work-around for me, though, which is to install pre-commit in the base env.) – someone Feb 20 '23 at 15:22

2 Answers2

3

Short answer

I have found this work-around for the problem:

Install and configure pre-commit in your base conda environment instead of your project's conda environment.

Details

I just reproduced this error a year later, getting an identical error log.

This happened when I was trying to run git commit with a Conda environment activated on Windows. While in that conda environment I was able to install packages, the mechanism by which pre-commit installs its hooks ended up broken, with SSL unavailable and the same log shown in the question.

The fix for me was to deactivate my conda environment, install pre-commit in my base conda environment, and do one commit with base activated. For some reason I still don't understand, SSL is available and works fine when pre-commit installs its hooks from the base conda env, but not from an activated project-specific environment.

Once the pre-commit hooks are installed and configured, then I can activate my project's conda environment and do further commits from there, since pre-commit reuses its cached installation of the hooks.

Full error log

Here's the error log on my machine, identical to what we can see on the screen shot in the question:

(my-conda-env) $ git commit
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\someone\\.cache\\pre-commit\\repot4mg0fom\\py_env-default\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing c:\users\someone\.cache\pre-commit\repot4mg0fom
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    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 with url: /simple/ruamel-yaml/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

stderr:
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
    ERROR: Could not find a version that satisfies the requirement ruamel.yaml>=0.15 (from pre-commit-hooks) (from versions: none)
    ERROR: No matching distribution found for ruamel.yaml>=0.15

Check the log at C:\Users\someone\.cache\pre-commit\pre-commit.log

After running conda deactivate:

(base) $ git commit
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check yaml...........................................(no files to check)Skipped
check json...........................................(no files to check)Skipped
fix end of files.....................................(no files to check)Skipped
[... rest of my checks]

I totally agree that this solution has bad smells: it's a work-around not a real fix. I agree that one should not install stuff in the base environment, and that all the project dependencies, including dev ones, should live in the project's venv. But... on Windows, this bug has affected both OP and myself.

E_net4
  • 27,810
  • 13
  • 101
  • 139
someone
  • 330
  • 8
  • 1
    Darn. Just faced the problem again in June 2023 and my solution did not work this time. However, I followed the [advice from johnkangw](https://github.com/pre-commit/pre-commit/issues/2813#issuecomment-1478377716) and created a venv, and then ran `pre-commit install-hooks`, and that worked. I'm more confused than I was before, but I have a working pre-commit again. – someone Jun 15 '23 at 21:01
  • Bless you. This was the fix after about 3 hours of trying. – Brandon Barkley Aug 04 '23 at 18:52
  • @BrandonBarkley curious: did the solution is my comment above work, on the one in the answer itself? – someone Aug 23 '23 at 14:25
  • I think it was the original answer. – Brandon Barkley Aug 24 '23 at 20:45
0

The screenshot is hard to read, but I don't think this has anything to do with ruamel.yaml. Try to install some other package and you are likely to get the same error.

You should make sure you have a newer 3.8 version installed, yours is 3.8.0 and the latest is 3.8.11. It your version is compiled from source, it might not have had all the libraries installed during compilation.

Anthon
  • 69,918
  • 32
  • 186
  • 246
  • That is not necessarily the case. I am able to install any package I want without any issue. I actually installed ruamel.yaml after running into this problem and you can see that it has been installed successfully. I don't mind updating the python version though, but so far that hasn't helped either – UGuntupalli Aug 16 '21 at 17:34