Skip to content

Instantly share code, notes, and snippets.

@Birch-san
Last active January 29, 2024 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Birch-san/c6584d4483deb0ce0b8be4561663ff01 to your computer and use it in GitHub Desktop.
Save Birch-san/c6584d4483deb0ce0b8be4561663ff01 to your computer and use it in GitHub Desktop.
Installing Python when behind a corporate proxy

Behind a corporate proxy? Can't add PPAs to your apt listings?

A typical HTTP proxy URL may look like:
http://proxy.mycoolproxy.com:8080

Let's configure all our tools to use this proxy.

apt

sudo nano /etc/apt/apt.conf.d/00proxy.conf
Acquire::http::Proxy "INSERTPROXYHERE";
Acquire::https::Proxy "INSERTPROXYHERE";
Acquire::ftp::Proxy "INSERTPROXYHERE";

wget
nano ~/.wgetrc:

use_proxy=yes
http_proxy=INSERTPROXYHERE
https_proxy=INSERTPROXYHERE

curl
nano ~/.curlrc:

proxy=INSERTPROXYHERE

pip (and others)
nano ~/.bashrc:

http_proxy=INSERTPROXYHERE
https_proxy=INSERTPROXYHERE
ftp_proxy=INSERTPROXYHERE

You can alternatively use apt install and pip install with a proxy on a one-off basis like so:

sudo http_proxy=INSERTPROXYHERE apt install whatever
pip install --proxy INSERTPROXYHERE whatever

Installing PPAs manually

Here's how to install python via the deadsnakes PPA, without using apt-key add or add-apt-repository (neither of which seem to work when behind proxy; maybe because they use HKPS protocol instead of HTTP, so don't honour proxy settings?):

Note: replace "focal" with whatever Ubuntu distribution you have, according to lsb_release -a.

curl -sSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF23C5A6CF475977595C89F51BA6932366A755776' | gpg --import
gpg --export F23C5A6CF475977595C89F51BA6932366A755776 | sudo tee /usr/share/keyrings/deadsnakes.pgp
echo "deb [signed-by=/usr/share/keyrings/deadsnakes.pgp] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu focal main" | sudo tee /etc/apt/sources.list.d/deadsnakes.list
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-distutils
python3.11 -m ensurepip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
sudo update-alternatives --install /usr/bin/pip pip /home/abirch/.local/bin/pip3 1
nano ~/.bashrc
PATH="$USER/.local/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment