pip install has SSL issue in virtualenv with interperter of python27 - python

TL;DR
Trying to use pip install within a python27 venv and got SSL connection error.
I am very new to python development. With the advent of python 3 and all the compatibility issues it introduced, I never felt so lost with so many python 2 codes and documentations active along with python 3 documentations.
So I am working with a python web app (flask based) which should be running on python 2.7.
I am running windows 10 with VS Code.
So I have done all the steps to create a venv folder under my project with the cmd virtualenv -p "C:\\Python27\python.exe" venv
When I start doing the pip install -r requirements.txt
I am getting following connection error.
c:\users\path\to\project\venv\lib\site-packages\pip_vendor\urllib3\util\ssl_.py:354:
SNIMissingWarning: An HTTPS request has been made, but the SNI (Server
Name Indication) extension to TLS is not available on this platform.
This may cause the server to present an incorrect TLS certificate,
which can cause validation failures. You can upgrade to a newer
version of Python to solve this. For more information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
Retrying (Retry(total=4, connect=None,
read=None, redirect=None, status=None)) after connection broken by
'SSLError(SSLError(1, '_ssl.c:499: error:1407742E:SSL
routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version'),)':
/simple/pip/
c:\users\kenzho~1\worksa~1\7eleve~1\venv\lib\site-packages\pip_vendor\urllib3\util\ssl_.py:150:
InsecurePlatformWarning: A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause
certain SSL connections to fail. You can upgrade to a newer version of
Python to solve this. For more information, see
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
I have tried following ways to address the issue.
python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --index-url=https://pypi.org/simple/
But none of them seems to work.
Any body got any idea?
Thanks

You need to update your Python SSL packages.
Option 1
Installing the following packages will fix the errors.
pip install pyOpenSSL ndg-httpsclient pyasn1
But this will only work for the system version of Python 2.7.6.
For some reason trying the same fix with a python in a virtual env fails hard. You end up not being able to complete the update because of the SSL error you are trying to fix.
Option 2
Upgrade your version of python. The fixes you need have been bundled into Python 2.7.9
Details of the error and fix are in the release notes.

Related

How to install PIP on python2.7 with python3 already installed, in Windows

I have already installed both Python 3.9.7 and Python 2.7 in my Windows. I need to install some libraries like scipy to run an old project, which is written in Python2.
It's a kinda big project so I prefer not to edit the syntax and make it compatible with Python3.
I have to install pip on my python2 for installing the required libraries. I tried to use the instructions mentioned here.
But I get this error:
c:\users\amerali\appdata\local\temp\tmponnk1_\pip.zip\pip\_vendor\urllib3\util\ssl_.py:164:
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/pip/
Which occurs 5-6times, then it gives the following error :
ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
ERROR: No matching distribution found for pip<21.0
I tried it with another internet connections as well, but didn't fix it.
Is there any solutions or an alternative way to install pip?

pip errors out with SSLError [X509] PEM lib (_ssl.c:4264) [Win10]

I can't update anything/install anything new using pip, the following error keeps occurring:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(9, '[X509] PEM lib (_ssl.c:4264)'))': /simple/<package>
I can install using the extended command
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
and I updated and force reinstalled my certifi package using this.
I thought it was a CA cert issue but, this didn't change anything with the normal command.
What's going wrong? (and how do I fix it?)
Update: I tried this before as well as mentioned in the question, but force-reinstalling certifi using the long command (with trusted hosts) solved it.
I cannot understand how it did not work when I asked the question.
One thing I can see being the problem is that when I did this the other day, it installed the most recent version of certifi at that time, which would be 2021.05.xx (may 2021 basically).
However, when it reinstalled today, it installed version 2021.10.8 (8th Oct 2021); which means a new update was released yesterday.
I wonder if I had installed an outdated/previous version (basically not the same version as 2021.05.xx), would it have worked?

Installing python library dependency without Internet available [duplicate]

This question already has answers here:
How to install packages offline?
(12 answers)
Closed 4 years ago.
I am trying to install the following package (SignXML) on Windows Server 2012: https://pypi.org/project/signxml/
I am running Python 2.7.14, it's an isolated server which is only accessible within Intranet and has all outbound connections blocked.
I've downloaded tar.gz of that package and executed: "pip install signxml-2.6.0.tar.gz".
It started installation but I get error:
Retrying (Retry(total=4, connect=None, read=None, redirect=None))
after connec tion broken by
'ConnectTimeoutError(, 'Connection to
pypi.python. org timed out. (connect timeout=15)')': /simple/lxml/
I am no expert with Python but I assume based on error that it attempts to retrieve some dependancy from pypi but fails as the outbound connections are blocked.
Is there a way to see all dependencies for that project (SignXML) and manually download them as tar.gz archives and then somehow manually install them or tell SignXML install to use local files instead of fetching them from Pypi?
I can understand you want to install signxml without internet as you downloaded .tar.gz file. But it requires some other dependencies too.
As per documentation https://pypi.org/project/signxml/
You will need to install other packages as - lxml, defusedxml, cryptography, eight, pyOpenSSL.
Please refer the documentation carefully.!
I don't think it's possible to be honest. Whether the file is a tar.gz, a .whl, or a straight up install call (like pip install pygame), it downloads it from the internet. The only way I could think of doing offline, is by extracting the contents you have and placing them in the
[python install dir]/Lib/site-packages
directory in it's own folder.
In the setup.py file of the package are the required packages listed. You probably need to install all of them manually.

Error while installing jupyter

I'm getting below error while installing Jupiter, does anyone came across similar issues.
pip3.5 install jupyter
Collecting jupyter
/grid/common/pkgs/python/v3.5.2/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
Could not fetch URL https://pypi.python.org/simple/jupyter/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) - skipping
Could not find a version that satisfies the requirement jupyter (from versions: )
No matching distribution found for jupyter
Here are the env details
OS: RHEL6
Python - 3.5.2
Pip: 9.0.1
Curl: 7.47.1
Openssl 1.0.1e
You can:
Go to Python root folder and run the "Install Certificates.command" file.
You may follow https://www.youtube.com/watch?v=BVS3U1OQzO4

How can I make PyCharm ignore SSL errors when installing libraries?

I am trying to install the requests library to my Python environment in PyCharm while on a company network that uses self-signed SSL certificates. As a result, installing a library with File > Settings > Project > Project Interpreter > Install fails with an HTTPS error:
Collecting requests
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection
broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.
VerifiedHTTPSConnection object at 0x0368D5D0>: Failed to establish a new connection:
[Errno 11003] getaddrinfo failed',)': /simple/requests/
Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
I tried making pip trust my company's root certificate by adding --cert C:\COMPANY-CAROOT.pem to my install options, which was interpreted as:
pip install --cert C:\COMPANY-CAROOT.pem requests
I also tried opening File > Settings > Project > Server Certificates and checking Accept non-trusted certificates automatically, but ran into the same issue.
How can I get PyCharm to ignore SSL certificate errors when installing external libraries?
I faced the same issue. The way I resolved it was by adding all the packages I wanted to install in a .txt file, e.g. requirements.txt containing all the package-names and their versions.
Then from the Terminal (can also be the PyCharm Terminal), I did:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt
The key here is the use of --trusted-host. Adding the packages in a file is just for convenience.
Alternatively you can create a pip.ini file and add the trusted hosts there.

Categories