Virtualenv: Can't install any package via `pip` on windows 10, ssl module in Python is not available

Created on 28 Feb 2018  ·  54Comments  ·  Source: pypa/virtualenv

python version: 3.6 (Intel Distribution for Python for Windows 2018 update 1)
virtualenv version: 15.1.0
windows version: windows 10 pro, build 17101.rs4_release.180211-1040

I executed only 2 commands, here is what Powershell output:

PS E:\Python\Virtualenv\Scripts> .\activate
(Virtualenv) PS E:\Python\Virtualenv\Scripts> pip install numpy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting numpy
  Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

This directory Python is not where the python installed, it is only a normal directory.

I have tried installing some standalone openssl, like the one from here, but neither of them worked.

Most helpful comment

I had the same issue. I was configuring a new computer with python and jupyter with anaconda, and the problem occured when I tried to install a package use pip.

Based on the discussions above, that this is an environment issue, I tried running "pip install" command in Anaconda Prompt instead of cmd. And the pip command was executed. 😁

All 54 comments

I assume the pip used is the one in your virtualenv. Is your _system_ pip able to install? If not, this might not be a virtualenv issue ...

@tobiasherp
System pip is ok, but the pip in the virtualenv does no good.
I don't know where the issue is, I can't even find a similar situation on Google. :(
Not only the numpy, it can't install any package online. But if there is a wheel file, it can be installed successfully, thus I think the problem might be related to the SSL.

Right, PyPI uses https now, so you need ssl support. If your system Python doesn't have it, your virtualenv won't have it either. With Python 3, you should be able to import an ssl module:

>>> import ssl

Your best bet might be to switch to an interpreter which has the ssl module.
The 3.6.4 interpreter I just now downloaded from https://www.python.org/ seems to have ssl support.

AFAICS, this is not a virtualenv issue; proposing to close it.

It might not be a venv problem but it is still a problem. In my instance I cannot install in venv or system pip
I have IntelPython3 installed on Win 10 64 bit and YES it has openssl installed and compiled but for some reason things does not work

I have seen this: [(https://software.intel.com/en-us/forums/intel-distribution-for-python/topic/737878#comment-1920719)]

But I could not fix my version of this problem.

Any advice on this issue would be very helpfull

@theCJMan are you still experiencing this problem?

I have up on that problem

On Tue, 17 Apr 2018, 19:44 Sumana Harihareswara, notifications@github.com
wrote:

@theCJMan https://github.com/theCJMan are you still experiencing this
problem?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/pypa/virtualenv/issues/1139#issuecomment-382081077,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AkTyyw5zfrJFZleItkAkrR1_kE9R-C8Cks5tpioOgaJpZM4SWUf4
.

Transport Layer Security, or TLS, is part of how we make sure connections between your computer and PyPI are private and secure. It's a cryptographic protocol that's had several versions over time.

You need to be connecting to PyPI with a TLS support library, such as a recent version of OpenSSL. The specific steps you need to take will depend on your operating system version, where your installation of Python originated (python.org, your OS vendor, or an intermediate distributor), and the installed versions of Python, setuptools, pipenv, and pip. For help, please go to the #pypa IRC channel on Freenode, file an issue at pypa/packaging-problems/issues, or post to the python-help mailing list, including your OS and installation details and the output of pip install -vvv upgrade pip.

I also experienced this on macos, python 2.7.15 - system python worked fine, virtual env failed to install due to

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

my system python imported ssl fine, but the venv python gave the following error:

raceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 126, in <module>
    from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_TLSv1_3
ImportError: cannot import name HAS_TLSv1_3

after deleting the env directory, and recreating the env, it all worked fine.

I got same issue as @liurui39660 , also using Intel Python Distribution and python -m venv to create my venv. It seems to be an issue with ssl module, having nothing to do with pip:

(venv) C:\Users\ceefour\git\tews\ecn-svc>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, May  3 2018, 23:39:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed: The operating system cannot run %1.
>>>

Note that the bug only triggered when using Intel Python inside a venv. When using the base env, it works:

(base) C:\Users\ceefour>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, May  3 2018, 23:39:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import ssl
>>> 

Update: This thread seems to be a clue:

Rohit J. (Intel) Thu, 07/06/2017 - 21:40
pip was unusable with both IDP and Miniconda on Windows. The problem was root-caused to a conflicting library (libeay32.dll) that was installed in system path. At run-time, loading of this library gained precedence over what we ship with our distribution. There was a version conflict and the execution would fail with "ImportError: DLL load failed: The operating system cannot run %1.". Removing this extraneous library from system path resolved the issue.

I have _lots_ of libeay32.dll inside of C:\Program Files, including one in C:\ProgramData\Anaconda3\Library\bin

I have tried moving C:\ProgramData\Anaconda3\Library\bin to front of PATH, but still error happens.

I had the same issue. I was configuring a new computer with python and jupyter with anaconda, and the problem occured when I tried to install a package use pip.

Based on the discussions above, that this is an environment issue, I tried running "pip install" command in Anaconda Prompt instead of cmd. And the pip command was executed. 😁

I am still struggling with following since yesterday, after installing Python 3.7.1 with Anaconda3

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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/pip/
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/pip/
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/pip/
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/pip/
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/pip/
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("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Requirement already up-to-date: pip in d:\anaconda3\lib\site-packages (18.1)
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

I had the same problem. Using willliu1995 suggestion solved the problem. Running pip from cmd prompt did nor work but launching jupyter notebook and running !pip install worked.

If pip install pandas is not working on CMD prompt, run this using Anaconda prompt - it works. You can find Anaconda prompt using this:

Go with the mouse to the Windows Icon (lower left) and start typing "Anaconda". There should show up some matching entries. Select "Anaconda Prompt". A new command window, named "Anaconda Prompt" will open. Source - https://stackoverflow.com/questions/47914980/how-to-access-anaconda-command-prompt-in-windows-10-64-bit

If you prefer to use the Windows Command Prompt instead, you will need to add the following directories to your Windows Environment path:
%Miniconda3_DIR%;%Miniconda3_DIR%\Library\mingw-w64\bin;%Miniconda3_DIR%\Library\usr\bin;%Miniconda3_DIR%\Library\bin;%Miniconda3_DIR%\Scripts;%Miniconda3_DIR%\bin;
[where, %Miniconda3_DIR% should be substituted by your Miniconda (or Anaconda) install path]

For example, I have my Miniconda installed at E:\Portable\Miniconda3. So my Windows PATH had to include these folders:
E:\Portable\Miniconda3;E:\Portable\Miniconda3\Library\mingw-w64\bin;E:\Portable\Miniconda3\Library\usr\bin;E:\Portable\Miniconda3\Library\bin;E:\Portable\Miniconda3\Scripts;E:\Portable\Miniconda3\bin;

@shriprem Thanks! It worked. Your solution confirms that this is a system path issue, since generally it's only necessary to add %Miniconda3_DIR%\Scripts to your PATH variable to use pip. Any idea why this has changed?

@EthanBackToLife I checked the PATH environment variable in the Anaconda prompt, and found that Anaconda was prefixing all those directories to its prompt PATH variable. So I appended the delta part of that path to the Windows PATH variable to confirm that it worked for pip.

While trying to install Conda on a different PC, I am able to refine the path changes to a much shorter: %Miniconda3_DIR%;%Miniconda3_DIR%\Scripts;%Miniconda3_DIR%\Library\bin
[On hindsight, we see that the other directories that were added to the path from my previous post are non-existent/empty on a fresh Conda install.]

With this narrowing down of the path, we can look at the %Miniconda3_DIR%\Library\bin folder. In here, we find files such as: libcrypto-1_1-x64.dll, libcrypto-1_1-x64.pdb, libssl-1_1-x64.dll, openssl.exe, libssl-1_1-x64.pdb, openssl.pdb which I think are critical in resolving the SSL/TLS issues with the pip (and conda) package installs.

python version: 3.6 (Intel Distribution for Python for Windows 2018 update 1)
virtualenv version: 15.1.0
windows version: windows 10 pro, build 17101.rs4_release.180211-1040

I executed only 2 commands, here is what Powershell output:

PS E:\Python\Virtualenv\Scripts> .\activate
(Virtualenv) PS E:\Python\Virtualenv\Scripts> pip install numpy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting numpy
  Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

This directory Python is not where the python installed, it is only a normal directory.

I have tried installing some standalone openssl, like the one from here, but neither of them worked.

I met the same question as you,and I tried to use the command .\activate ,then settled the question perfectly,I couldn't thank you anymore.

@EthanBackToLife I checked the PATH environment variable in the Anaconda prompt, and found that Anaconda was prefixing all those directories to its prompt PATH variable. So I appended the delta part of that path to the Windows PATH variable to confirm that it worked for pip.

While trying to install Conda on a different PC, I am able to refine the path changes to a much shorter: %Miniconda3_DIR%;%Miniconda3_DIR%\Scripts;%Miniconda3_DIR%\Library\bin
[On hindsight, we see that the other directories that were added to the path from my previous post are non-existent/empty on a fresh Conda install.]

With this narrowing down of the path, we can look at the %Miniconda3_DIR%\Library\bin folder. In here, we find files such as: libcrypto-1_1-x64.dll, libcrypto-1_1-x64.pdb, libssl-1_1-x64.dll, openssl.exe, libssl-1_1-x64.pdb, openssl.pdb which I think are critical in resolving the SSL/TLS issues with the pip (and conda) package installs.

Great explanation! Thank you.

I still have this problem after doing what @shriprem commented. Python version 3.7.1 and pip version 18.1, if that helps.

" I can solve this problem by adding dir path of intel-python which has libeay32.dll (in my case ..\IntelPython3\pkgs\openssl-1.0.2l-vc14_intel_0\Library\bin) in system environment as top most position."

reference: https://software.intel.com/en-us/forums/intel-distribution-for-python/topic/737878

I've found being in the "Scripts" directory is required to use pip

For Windows 10 If pip install is not working on CMD prompt, run it using Anaconda prompt - it works.

If you want use pip in normal CMD, not only in Anaconda prompt.
you need add 3 environment paths.
like these:
D:\Anaconda3;
D:\Anaconda3\Scripts;
D:\Anaconda3\Library\bin

most people only add D:\Anaconda3\Scripts;

Specify path C:\Anaconda3\Library\bin in environment user variables.
Or
Just check wheather you have openssl installed in base python
If not just install using following command
pip install pyopenssl

I believe the paths are added correctly, but pip is still not working, either on CMD or on Anaconda prompt.

did you try from the "Scripts" directory?

did you try from the "Scripts" directory?

If you mean cd xxx/Scripts and then pip install, I tried just now and it's not working.

@SnarkyPapi, you say "I believe the paths are added correctly." To confirm this fact, run the 4 commands listed in bold below.

  1. Command: > where python
    Output should be something like: _C:\Miniconda3-x64\python.exe_

  2. Command: > where pip
    Output should be something like: _C:\Miniconda3-x64\Scriptspip.exe_

  3. Command: > where openssl
    Output should be something like:
    [Note that it's possible that openssl.exe is installed in multiple locations of the environment path. In my case, openssl has also been installed as part of the Perl installation]
    _C:\Perl\c\bin\openssl.exe
    C:\Miniconda3-x64\Library\bin\openssl.exe_

  4. Command: > where libssl-1_1-x64.dll
    Output should be something like: _C:\Miniconda3-x64\Library\bin\libssl-1_1-x64.dll_

For any of these, if you get an output that says "INFO: Could not find files for the given pattern(s).", then one of the required path components needed for pip is missing for your environment.

Hi, the 4 commands worked well, and for the 4th one it shows 2 lines:
C:\Windows\System32\libssl-1_1-x64.dll
C:\Anaconda\Library\bin\libssl-1_1-x64.dll

looks like you might want to put "C:\Anaconda\Library\bin" at the start of your $PATH

looks like you might want to put "C:\Anaconda\Library\bin" at the start of your $PATH
Just tried it and the problem is still there.

can you echo %PATH%

you might have open a new terminal for the PATH to change

Alternative solution: I just managed to make it work by creating a pip.ini file under C:\Users\my_user_namepip, writing:

[global]
index-url=http://pypi.douban.com/simple/
[install]
trusted-host=pypi.douban.com

It solves the problem for the moment, however the download speed using this mirror is not really fast (around 800kb/s). Is there a way to make it work as usual?

can you echo %PATH%

you might have open a new terminal for the PATH to change

C:\Anaconda\Library\bin;D:\Software\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;D:\Software\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Razer Chroma SDK\bin;D:\Software\Razer Chroma SDK\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Software\PuTTY\;C:\windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;D:\Software\dotnet\;D:\Software\MySQL\MySQL Utilities 1.6\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Software\Git\cmd;C:\Users\Cyrilpippip.ini;C:\Anaconda;C:\Anaconda\Library\mingw-w64\bin;C:\Anaconda\Library\usr\bin;C:\Anaconda\Scripts;C:\Anaconda\bin;C:\Anaconda\Library\bin;C:\Anaconda;C:\Anaconda\Library\mingw-w64\bin;C:\Anaconda\Library\usr\bin;C:\Anaconda\Scripts;C:\Anaconda\bin;D:\Software\Docker Toolbox;C:\Users\Cyrilpippip.ini;

SSL libraries are in your C:\anaconda\Library\bin folder. You have to have that path set at the moment of trying to install your libraries. This is because, when you activate a virtual environment, the PATH is changed.

Therefore,

  • If you do not use virtual environments, manually set the PATH to:
set PATH=C:\anaconda;C:\anaconda\Scripts;C:\anaconda\Library\bin
pip  install any_library
or
pip install -r requirements.txt

  • If you do use virtual environments, manually set the PATH to:
set PATH=C:\venvs\ve1\;C:\venvs\ve1\Scripts;C:\anaconda\Library\bin
pip  install any_library
or
pip install -r requirements.txt

Note that C:\anaconda\Library\bin is consistent in both cases, regardless if you are working in a vm or not.

@datatravelgit Hi, I am not using virtual environments and there is still this problem after setting path manually.

Thanks for the helpful comments above! Adding the following to the path variable worked for me on Windows 10:
C:\Users...\Anaconda3
C:\Users...\Anaconda3\Scripts
C:\Users...\Anaconda3\Library\bin

I got same issue as @liurui39660 , also using Intel Python Distribution _and_ python -m venv to create my venv. It seems to be an issue with ssl module, having nothing to do with pip:

(venv) C:\Users\ceefour\git\tews\ecn-svc>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, May  3 2018, 23:39:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed: The operating system cannot run %1.
>>>

Note that the bug only triggered when using Intel Python inside a venv. When using the base env, it works:

(base) C:\Users\ceefour>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, May  3 2018, 23:39:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import ssl
>>> 

Update: This thread seems to be a clue:

Rohit J. (Intel) Thu, 07/06/2017 - 21:40
pip was unusable with both IDP and Miniconda on Windows. The problem was root-caused to a conflicting library (libeay32.dll) that was installed in system path. At run-time, loading of this library gained precedence over what we ship with our distribution. There was a version conflict and the execution would fail with "ImportError: DLL load failed: The operating system cannot run %1.". Removing this extraneous library from system path resolved the issue.

I have _lots_ of libeay32.dll inside of C:\Program Files, including one in C:\ProgramData\Anaconda3\Library\bin

I have tried moving C:\ProgramData\Anaconda3\Library\bin to front of PATH, but still error happens.
-------------更新:20190327
刚qq来了个邮件,点进来才发现是这个问题,这个后来解决了。我在电脑上重新安装了Win64OpenSSL_Light-1_1_1b.exe ,然后anaconda卸载并重装。现在anaconda和python都正常了。

-------------以下为旧内容
谢谢,我昨天也遇到了相同的问题,然后我把Anaconda卸载后重装了,但并没有解决。刚才我从单独的目录中执行import ssl,anaconda中的报错,另外一个不报错。如图:
GitHub Logo
我把pycharm中的路径修改后,pycharm也可以正常运行了。

I had to replace the libssl-1_1-x64.dll in my envs/myenv/Library/bin folder with the base env dll. It was not the same one. Plus I had another libssl-1_1-x64.dll under C:/Windows/System32/ and under certain Intel folders in C:/Program Files. I removed the Intel stuff from the path and deleted the one under system32.

Not sure when the corrupt dll has been copied, but replacing it with the one from conda/Library/bin/ worked well.

To further check errors, you could activate your environment and type python -c "import ssl". It's an important difference, if the error is "Module not found" (-> dll cannot be found at all, might be a Path problem) or "Procedure entry point not found" (-> likely, a corrupt/wrong dll is found).

I had to replace the libssl-1_1-x64.dll in my envs/myenv/Library/bin folder with the base env dll. It was not the same one. Plus I had another libssl-1_1-x64.dll under C:/Windows/System32/ and under certain Intel folders in C:/Program Files. I removed the Intel stuff from the path and deleted the one under system32.

Not sure when the corrupt dll has been copied, but replacing it with the one from conda/Library/bin/ worked well.

To further check errors, you could activate your environment and type python -c "import ssl". It's an important difference, if the error is "Module not found" (-> dll cannot be found at all, might be a Path problem) or "Procedure entry point not found" (-> likely, a corrupt/wrong dll is found).

Im experiencing same issue- "The specified procedure could not be found." - only in specifc env.
In base env "import ssl" works well.

Tried replacing env's libssl-1_1-x64.dll with the base env's libssl-1_1-x64.dll - but didnt help.
Could there be any other file that's causing this?

Fixed for me, thanks for everyone's comments.
The issue wasn't fixed by adding \Anaconda3\Library\bin to the path, or even the top of the path. The same is true for \Anaconda3\Scripts and \Anaconda3\Library\mingw-w64\bin.

Tried replacing env's libssl-1_1-x64.dll with the base env's libssl-1_1-x64.dll - but didnt help.
Could there be any other file that's causing this?

Removing both libssl-1_1-x64.dll and libcrypto-1_1-x64.dll in C:/Windows/System32/ fixed the problem for me.

I love you buddy!
Removing both libssl-1_1-x64.dll and libcrypto-1_1-x64.dll in C:/Windows/System32/ fixed the problem for me.

install Win64OpenSSL_Light-1_1_1b.exe https://slproweb.com/download/Win64OpenSSL_Light-1_1_1b.exe ,then pip works well.

try using:

pip3 install <package>

this problem can be solved by changing the path through this pc
go to properties
then go to advance settings
then environment variables
then system variables
then path
double click path
check the path of installed python
if you have anaconda
then delete both paths and
then click new
then copy the path of python 3.7 or latest python til scripts i.e
(C:\Users\'user name'\AppData\Local\ProgramsPythonPython37\scripts)
then click ok
next also click new
then copy the path C:\Users\'user name'\AppData\Local\ProgramsPythonPython37
then restart the cmd as admin and retry installation

Funny thing: I had the same problem on Android, Termux. Pip could not connect to pypi.org due to absent ssl.
The problem is clearly with ssl module. So, initially check, if you have any ssl installed. If yes, upgrade it to the latest versions, as ssl algorithms evolve quickly, and become incompatible.
Try either to update existing library, or install a better supported package.

For Anaconda/Miniconda users on Windows, this is a library load issue. There's information in the troubleshooting FAQ at https://conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#condahttperror-http-000-connection-failed

As some users have noted, other installations of openssl into the Windows\System32 folder can be exceptionally troublesome. There's information about a workaround in Anaconda's (and conda-forge's) python in this related troubleshooting section: https://conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed

You can report anaconda issues at https://github.com/continuumio/anaconda-issues

I had a recurrence of the SSL issue with pip module installs. Before this, pip had worked fine for several months -- after correctly configuring the environment path to include the 3 conda folders: %Conda_DIR%;%Conda_DIR%\Scripts;%Conda_DIR%\Library\bin.

After a couple of hours of wrangling, I arrived at these two solutions -- one for module installs via pip, and the other for those via conda.

Module installs via pip

Basically, based on the error messages, I had to add pypi.org and files.pythonhosted.org sites as trusted hosts.

You could do this once via: pip config set global.trusted_host "pypi.org files.pythonhosted.org"
This setting change is saved in C:\Users\user_name\Appdata\Roaming\pip\pip.ini (in short, %APPDATA%\pip\pip.ini) file. Since this is in a non-administrator user folder from the Windows perspective, it should be safe to do so.

[If you are not comfortable with the 'global' setting change, you could repeat this during every module install.
For example: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -U matplotlib]

Module installs via conda

Some Python modules like basemap don't install via pip. I had to use conda instead.
To override the SSL error with conda, I had to use: conda config --set ssl_verify false

[After the conda module install, I turned the ssl back on with: conda config --set ssl_verify true]

While resolving these issues today, the general info at https://conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#ssl-connection-errors and the specific sites info from the install-time error messages -- both proved helpful.

Hi when in the anaconda prompt i am unable to use pip due to TSL/SSL issues:

(base) C:\Users\joshu>pip install pandahouse
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

But i am able to pip install anything I want when using python native:

C:\Users\joshu\AppData\Local\Programs\Python\Python37\Scripts>pip install scrapy
Collecting scrapy
  Downloading http....

What I've done so far:

  1. Installed Python first
  2. Installed anaconda
  3. Reinstalled anaconda
  4. Removed libcrypto-1_1-x64.dll and libssl-1_1-x64.dll from System32/
  5. Added my Anaconda libraries to the top system and user variables of PATH
    C:\Users\joshu\Anaconda3\Library\bin
  6. Still does not work

CMD Prompt Locations in native Python:

C:\Users\joshu\AppData\Local\Programs\Python\Python37\Scripts>where libssl-1_1-x64.dll
C:\Users\joshu\Anaconda3\Library\bin\libssl-1_1-x64.dll

C:\Users\joshu\AppData\Local\Programs\Python\Python37\Scripts>where libcrypto-1_1-x64.dll
C:\Users\joshu\Anaconda3\Library\bin\libcrypto-1_1-x64.dll

Anaconda Prompt locations:

(base) C:\Users\joshu>where libssl-1_1-x64.dll
C:\Users\joshu\Anaconda3\Library\bin\libssl-1_1-x64.dll

(base) C:\Users\joshu>where libcrypto-1_1-x64.dll
C:\Users\joshu\Anaconda3\Library\bin\libcrypto-1_1-x64.dll

Not sure if this matters but OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg appears above PATH in my system variables.

Could someone please help I am not sure how to solve this and would really prefer using Anaconda/Spyder instead of native python

@jmhcodes, check out this link: https://stackoverflow.com/questions/41328451/ssl-module-in-python-is-not-available-when-installing-package-with-pip3

Also on stackoverflow, I came across another discussion that was more relevant to the sudden recurrence of the SSL certificate verify error that I started facing on my work PC. The discussion link is: https://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi

In a couple of those answers, there were these statements:

In my case, the certificates in my company's network was the issue.

and

I recently ran into this problem because of my company's web content filter that uses its own Certificate Authority so that it can filter SSL traffic.

So in my case, it was the corporate network firewall that broke my pip. But adding files.pythonhosted.org & **pypi.org as trusted hosts has resolved the issue for now.

Honestly, I hadn't seen the 2nd stackoverflow discussion when I had resolved the issue last week, and posted my solution steps here. A majority of responses in the stackoverflow article agree that using --trusted-host solved their pip issues as well. In addition to the two sites mentioned above, they also recommend adding pypi.python.org

@shriprem

@jmhcodes, check out this link: https://stackoverflow.com/questions/41328451/ssl-module-in-python-is-not-available-when-installing-package-with-pip3

Also on stackoverflow, I came across another discussion that was more relevant to the sudden recurrence of the SSL certificate verify error that I started facing on my work PC. The discussion link is: https://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi

I've seen these two posts as well and I could add it as a global trusted host and walk away but I am not comfortable enough to do so.

What I am really aiming to answer is why pip works without SSL/TSL issues within the native python package in the cmd line BUT does not work in the anaconda prompt even though openssl/libssl-1_1-x64.dll/libcrypto-1_1-x64.dll all point to the same location.

@jmhcodes, run the command where pip.exe within both the regular command prompt and the Anaconda prompt. Do they both return the same path to pip.exe?

Here are some of the differences that the Anaconda prompt brings to its environment over the regular command prompt:

  1. Anaconda prefixes 7 of its subdirectories at the very front of the regular environment path. You can check this by running the command echo %path% from within both environments and diffing them. Those 7 subdirectories are:
    %CONDA_DIR%; %CONDA_DIR%\Library\mingw-w64\bin; %CONDA_DIR%\Library\usr\bin; %CONDA_DIR%\Library\bin; %CONDA_DIR%\Scripts; %CONDA_DIR%\bin; %CONDA_DIR%\condabin;

_Note: %CONDA_DIR% should be substituted with your Anaconda install path._

  1. Anaconda also defines these new environment variables:
    CONDA_DEFAULT_ENV, CONDA_EXE, CONDA_PREFIX, CONDA_PROMPT_MODIFIER, CONDA_PYTHON_EXE, CONDA_SHLVL, PYTHONIOENCODING, PROJ_LIB, _CONDA_SET_PROJ_LIB
    You can verify this by running the command set from both environments and diffing them.

These differences between the two environments could be causing whatever issues you are having. It is up to you to dig further.

But if pip.exe is pointing to the same binary from both environments, you shouldn't be very much concerned about which environment you are using to run pip. Also, I wouldn't be too concerned about adding the very well known python.org pip sites as trusted hosts. So were many at stackoverflow. That's my two cents.

Lastly, you mentioned:

Not sure if this matters but OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg appears above PATH in my system variables.

That's because the system variable OPENSSL_CONF comes before PATH when being listed in the alphabetical order. So it shouldn't matter for the issue you are having. Or did I misinterpret what you were saying?

Anaconda Promt
pip 19.1.1 from C:\ProgramData\Anaconda3\lib\site-packages\pip (python 3.7)

Cmd prompt
C:\Users\joshu\AppData\Local\Programs\Python\Python37\Scripts\pip.exe

But i cant even open spyder/anaconda nav or anything else related to the anaconda suite other than anaconda prompt:

(base) C:\Users\joshu>spyder.exe
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\external\github.py", line 51, in <module>
    from urllib2 import build_opener, HTTPSHandler, Request, HTTPError
ModuleNotFoundError: No module named 'urllib2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3285, in main
    mainwindow = run_spyder(app, options, args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3140, in run_spyder
    main.setup()
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 809, in setup
    from spyder.plugins.console import Console
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\console.py", line 37, in <module>
    from spyder.widgets.reporterror import SpyderErrorDialog
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\reporterror.py", line 26, in <module>
    from spyder.widgets.github.backend import GithubBackend
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\github\backend.py", line 33, in <module>
    from spyder.utils.external import github
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\external\github.py", line 58, in <module>
    from urllib.request import build_opener, HTTPSHandler, HTTPError, Request
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (C:\ProgramData\Anaconda3\lib\urllib\request.py)

I work with visual studio Code and I had the same problem it was because doesn't was active conda virtual env I executed that

imagen

Was this page helpful?
0 / 5 - 0 ratings