Error when installing matplotib in Slicer

I’m trying to install matplotlib package in python-interactor in Slicer 5.0.2 with the following commands:

from slicer.util import pip_install
pip_install("matplotlib")
import matplotlib.pyplot as plt

I get the following error:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))': /simple/matplotlib/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))': /simple/matplotlib/
Could not fetch URL https://pypi.org/simple/matplotlib/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/matplotlib/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))) - skipping
ERROR: Could not find a version that satisfies the requirement matplotlib (from versions: none)
ERROR: No matching distribution found for matplotlib
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)'))) - skipping
Traceback (most recent call last):
  File "D:/DESKTOP/ex/module3/module3.py", line 480, in readPic
    pip_install("matplotlib")
  File "E:\Slicer 5.0.2\bin\Python\slicer\util.py", line 3431, in pip_install
    _executePythonModule('pip', args)
  File "E:\Slicer 5.0.2\bin\Python\slicer\util.py", line 3394, in _executePythonModule
    logProcessOutput(proc)
  File "E:\Slicer 5.0.2\bin\Python\slicer\util.py", line 3363, in logProcessOutput
    raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command '['E:/Slicer 5.0.2/bin/../bin\\PythonSlicer.EXE', '-m', 'pip', 'install', 'matplotlib']' returned non-zero exit status 1.
...

as shown in the picture:

There seems to be an SSL error. There could be many reasons. Using the current Slicer version (5.2.2) may fix the problem. Let us know if the problem occurs in current Slicer version, too.

Yes, it still occurs…

I encountered something very similar when I started a clean build of a Slicer custom app. This was the original error:

  Performing install step for 'python-pip'
  CMake Error at E:/t/tR/slicersources-build/python-pip-prefix/src/python-pip-stamp/python-pip-install-Release.cmake:49 (message):
    Command failed: 1
     'E:/t/tR/python-install/bin/PythonSlicer.exe' '-m' 'pip' 'install' '--require-hashes' '-r' 'E:/t/tR/python-pip-requirements.txt'
    See also
      E:/t/tR/slicersources-build/python-pip-prefix/src/python-pip-stamp/python-pip-install-*.log 

In the log file there was something like this:

  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)'))': /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)'))': /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)'))': /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)'))': /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)'))': /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))

WARNING: You are using pip version 22.0.3; however, version 23.0.1 is available.
You should consider upgrading via the 'E:\dt\dR\python-install\bin\python.exe -m pip install --upgrade pip' command.

First it happened with python-setuptools then python-pip, without changing anything. In the latter case it complained about pip version so I copied over the pip to site-packages from another, formerly successful build and then the build continued, but the same type of error happened with python-numpy, so I figured the problem is more central. Then I tried building another custom app, and the problem was the same, although that custom app was built successfully before. I think something may have changed in the infrastructure in the past 5-10 days.

Next I’m building a Slicer on the same machine, and will start both a custom app and a Slicer build on another machine on another network to try to pinpoint the issue, but I thought it’d be useful to share this info now in case it helps.

Thanks for sharing :grin:. Let’s wait for a solution.

Try to disable third-party antivirus software if you have any (see here). It might also worth trying this.

I built regular Slicer (latest commit) and it failed the same way. At the same time on a different computer/network the build succeeded. It is a home computer so there should be no network limitations but evidently there is something. Thanks for the suggestions @lassoan I’ll look into those.

I didn’t have any 3rd party antivirus, but trying the second link worked (in the sense that pip installing matplotlib as mentioned first in this topic succeeded).

In summary, the file c:\Windows\System32\Drivers\etc\hosts had to be opened with a text editor started as administrator, then these two lines added to the end:

151.101.0.223 pypi.org
151.101.1.63 files.pythonhosted.org

I’m building Slicer and the custom apps to confirm that everything works.

I’m a bit puzzled, because I didn’t install any relevant-looking application lately, nor have I made changes in firewall or other network settings, didn’t change internet providers etc, so all in all there have been no changes. Still, using pip worked perfectly before, and suddenly this problem started occurring. It would be interesting to know what caused it. But it’s great that it seems to be working now (pending the builds), thanks a lot @lassoan!

@hapkx I marked Andras’ suggestion solution because it helped me, but please confirm it works for you as well, since this topic is coming from your side.

The second one works! Thank you! :blush:

@cpinter I’m just curious, do you have optical fiber connection to your internet service provider? Does disabling “TCP and UDP Checksum Offload for IPv6” (or TCP/IPv6 protocol completely) fixes the issue as well?

From https://www.reddit.com/r/Fios/comments/xo55n4/verizon_just_activated_ipv6_turning_off_ipv6_tcp/ :

  1. Open the “Network Connections” page of the Windows Control Panel.
  2. Open the “Properties” dialog of the NIC.
  3. Select “Configure…” to open the NIC’s configuration.
  4. Navigate to the Advanced tab and disable “TCP and UDP Checksum Offload for IPv6”.

Yes.

Well, maybe I need some help. My Windows is set to English, but it was originally Spanish, and some parts are apparently not converted to English. Here’s the page in question:

image

I guess the checksum offload is the one selected. But there are five of them, and Windows doesn’t let me resize this window and there are no tooltips either to see the end of these strings. I don’t want to just disable all of them because I don’t want to potentially break something.

Can you please check on your machine what are these four exactly? Maybe then we can guess the order of these and I can disable just the TCP and UDP ones.

Well considering what could break I gave it a go anyway. I disabled all five, and it did not fix the issue.

Here is my network interface properties list:

You can try temporarily disabling TCP/IPv6 to see if it makes a difference, just for testing.

OK I’ll try to disable IPv6 when appropriate. @hapkx if you’d like to help out you could try this one.