POSTS / Using Proxy While Installing Packages via Pip
Pip using Proxy
via Command
Reference: pip documentation: pip —proxy.
According to this guide, you can use pip like this to install packages:
pip install --proxy http://<usr_name>:<password>@<proxyserver_name>:<port#> <pkg_name>
Leave it empty if there’s no usr_name
or password
such as:
pip install --proxy http://<proxyserver_name>:<port#> <pkg_name>
Also, you can set the proxy server environment variables to enable the proxy:
export http_proxy=http://<usr_name>:<password>@<proxyserver_name>:<port#>
via Config
Reference: pip documentation: configuration and pip documentation: pip config.
As this guide, you can specify a proxy for pip in the config file so that you can use an usual command to install packages.
You can use this command to preset pip options to current environment configuration file:
pip config set global.proxy http://<usr_name>:<password>@<proxyserver_name>:<port#>
Here’s the description of pip config
:
Description Manage local and global configuration.
Subcommands:
- list: List the active configuration (or from the file specified)
- edit: Edit the configuration file in an editor
- get: Get the value associated with command.option
- set: Set the command.option=value
- unset: Unset the value associated with command.option
- debug: List the configuration files and values defined under them
Configuration keys should be dot separated command and option name, with the special prefix “global” affecting any command. For example, “pip config set global.index-url https://example.org/” would configure the index url for all commands, but “pip config set download.timeout 10” would configure a 10 second timeout only for “pip download” commands.
If none of —user, —global and —site are passed, a virtual environment configuration file is used if one is active and the file exists. Otherwise, all modifications happen to the user file by default.