25

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

4 Answers 4

38

Space-separated, not comma-separated:

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

or

[global]
trusted-host = pypi.org
               files.pythonhosted.org
4
  • Can you provide a reference for future use? Also, how would I do that via pip config set?
    – oxr463
    Commented Dec 11, 2019 at 16:40
  • 10
    I just stole it as an example from stackoverflow.com/a/52054867/7976758. pip config set global.trusted-host="pypi.org files.pythonhosted.org", I suppose.
    – phd
    Commented Dec 11, 2019 at 16:47
  • 1
    @phd pip config set [name] [value] should be used, the = sign should be removed.
    – Gary Wang
    Commented Jun 25, 2023 at 3:26
  • 2
    @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
    Commented Jun 25, 2023 at 9:41
24

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]")
3
  • 1
    Upvoted. Easy to put in Dockerfile in case build is happening with SSL interception (proxy) Commented Aug 3, 2021 at 6:09
  • Thanks...this worked, no equals sign!
    – slackjake
    Commented Apr 8, 2022 at 5:55
  • Neat, thanks for that
    – Juliusz
    Commented Aug 13 at 8:20
14

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

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.