The following guide shows how to install python packages behind a firewall using the trusted-host option with the pip command.
This is typically needed when a ConnectTimeoutError is received when you are attempting to install python packages.
Option 1: Adding an option to the pip command in the shell
The first option involves adding a trusted-host option each time pip is called in the shell.
pip install <package-name> pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
Option 2: Adding configuration option in Pycharm
If you are installing packages from the Pycharm IDE, you can set the trusted host(s) within the Option field.
The following command is added to the Option field
pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
Option 3: One-off configuration in the shell
The third option is the best to use for a long-term solution. In this case a trusted hosts are set within a configuration file which is checked whenever pip is called (either in the shell or in Pycharm).
pip config set global.trusted-host "pypi.org files.pythonhosted.org"
A screenshot of the pip config command being called is shown below.
The contents of the pip configuration file after the command is called is shown below, viewed using the Notepad++ editor.