19

This is what I tried setting in my /etc/pip.conf:

[global]
trusted-host = pypi.org, files.pythonhosted.org

However, it is not working properly.

References:

See also: pip.conf not paying attention to trusted-host

oxr463
  • 1,573
  • 3
  • 14
  • 34

4 Answers4

33

Space-separated, not comma-separated:

[global]
trusted-host = pypi.org files.pythonhosted.org

or

[global]
trusted-host = pypi.org
               files.pythonhosted.org
phd
  • 82,685
  • 13
  • 120
  • 165
  • Can you provide a reference for future use? Also, how would I do that via `pip config set`? – oxr463 Dec 11 '19 at 16:40
  • 10
    I just stole it as an example from https://stackoverflow.com/a/52054867/7976758. `pip config set global.trusted-host="pypi.org files.pythonhosted.org"`, I suppose. – phd Dec 11 '19 at 16:47
  • 1
    @phd `pip config set [name] [value]` should be used, the `=` sign should be removed. – Gary Wang Jun 25 '23 at 03:26
  • @GaryWang Yep, you're right, my bad, thanks for spotting! Too late to edit the comment so here is the fixed version: `pip config set global.trusted-host "pypi.org files.pythonhosted.org"` – phd Jun 25 '23 at 09:41
16

This worked for me using the command line, Python 3.9.1, pip 20.2.3, & a virtual environment. No equals sign after "global.trusted-host".

pip config set global.trusted-host "pypi.org files.pythonhosted.org pypi.python.org"

Motivation: I don't want to disconnect from a VPN or specify --trusted-host each time I install a package.

pip config list

Produces the following:

global.trusted-host='pypi.org files.pythonhosted.org pypi.python.org'

DID NOT work:

pip config set global.trusted-host="pypi.org files.pythonhosted.org pypi.python.org"

ERROR: Got unexpected number of arguments, expected 2. (example: "pip config set [name] [value]")
Jason Cook
  • 1,236
  • 9
  • 12
12

To do from the command line python -m pip config set global.trusted-host=pypi.org files.pythonhosted.org

Dave Edwards
  • 121
  • 1
  • 2
3

If you are facing following issue while using pip install application_name:

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

The following solution will help solve the problem:- First find the pip location. For this you can run the following command-

pip config -v list

The default recommended location for pip creation is:

C:\Users\your_username_here\AppData\Roaming\pip\pip.ini

You need to append the following lines manually-

[global]
trusted-host = pypi.org files.pythonhosted.org

Instead of manually creating the pip.ini file at the above location, please run the following command line prompt-

python -m pip config set global.trusted-host=pypi.org files.pythonhosted.org

Remember it takes only 2 locations to be trusted. If you provide the 3rd one, then it will throw an error. Once successful, it will create the pip.ini file at the above location automatically and it is better than manual steps.

After this commands like the following should work without an error-

pip install virtualenv

I have tried the above steps in Windows 10 home edition and it worked for me.

Hope this summary helps!

Agarwal
  • 31
  • 1
  • Thanks bud much easier than typing the trusted host lines with every call to pip on my corporate PC. – Matt Feb 16 '22 at 15:30