How to use pip with socks proxy?
Asked Answered
D

8

14

I'm using ssh -D to create a socket proxy and want to know how to use pip(or easy_install) with it? I find this question but that's an http proxy.

Also, please give me a solution works under OS X. (I tried proxifier, it works with pip install, but not sudo pip install)

Decumbent answered 7/4, 2014 at 14:44 Comment(0)
D
16

Use socks proxifier, for example proxychains.

Command pip will be like proxychains pip install package_name.

Or use another proxifier.

Dixie answered 6/8, 2014 at 7:8 Comment(2)
if you're coming here since 2020, you'll probably have better luck with github.com/rofl0r/proxychains-ng instead of the mentioned SourceForge link.Paschasia
proxychains doesn't work for me for pip (or git) - but proxychains-ng did! * proxychains did work for apt though...Cavatina
A
33

Easiest method, also works on many OS's:

pip install pysocks
pip install <yourpacakge> --proxy socks5://127.0.0.1:8123

Substitute socks4, and your own ip/port as needed.

Aftershaft answered 22/12, 2018 at 10:5 Comment(7)
"AssertionError: Not supported proxy scheme socks5"Willock
Unfortunately, if you need a proxy to get pip connected, this is not going to workDisenchant
@mark pip has a bootstrapping shell scripts that you can use with more traditional proxy params. ie: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py .Aftershaft
@VladimirPanteleev Did you try socks4? Possibly you need a newer version of python for this to work (I typically use 3.6)Aftershaft
My solution was to install python3-pysocks via yum with appropriate SOCKS proxy settings in /etc/yum.conf, then run the second command.Fyrd
do you mean socks5://127.0.0.1:8123?Clearcole
hmm, it depends. on my install the "://" doesn't workAftershaft
D
16

Use socks proxifier, for example proxychains.

Command pip will be like proxychains pip install package_name.

Or use another proxifier.

Dixie answered 6/8, 2014 at 7:8 Comment(2)
if you're coming here since 2020, you'll probably have better luck with github.com/rofl0r/proxychains-ng instead of the mentioned SourceForge link.Paschasia
proxychains doesn't work for me for pip (or git) - but proxychains-ng did! * proxychains did work for apt though...Cavatina
F
6

For CentOS, you can use privoxy to convert socks5 proxy to http proxy.

yum install privoxy

Then edit /etc/privoxy/config, at the end of the file, add:

forward-socks5 / 127.0.0.1:1080 .

It will convert socks5 proxy from 1080 to http proxy 8118. Then you can specify the proxy in your pip config file:

[global]
proxy = 127.0.0.1:8118

DO NOT use polipo, as it is already deprecated.

Fye answered 24/10, 2016 at 9:12 Comment(0)
D
4

As other users have posted the following works well for using pip via a remote host:

# SOCKS4 proxy creation
ssh -D9999 <remote host URI>
# use pip with the previously created proxy connection (requires pysocks)
python3 -m pip install <package name> --proxy socks5:localhost:9999

Bootstrapping

"But I need pysocks to run pip through a proxy and you can't connect to the pypi to download packages as I don't have functioning pip"

One way to get around this is to download the pysocks wheel package on another machine:

python3 -m pip download pysocks

This will download the pysocks package to your machine. Transfer the PySocks-x-x-x-py3-none-any.whl file to the machine that requires proxy functionality and install:

python3 -m pip install PySocks*.whl
Disenchant answered 11/8, 2021 at 16:12 Comment(0)
K
3

Run these two commands:

pip install pysocks5
pip install --proxy socks5://[user:passwd@]proxy.server:port something
Kwangtung answered 7/7, 2019 at 10:40 Comment(1)
These days it appears the package is just pysocks and you can invoke it with socks4 or socks5 protocols.Bluegreen
H
1

Nevermind, --proxy seems to work with http(s) proxy only.

From "pip --help"

--proxy <proxy>             Specify a proxy in the form
                          [user:passwd@]proxy.server:port.

Edit: I finally gave up sock proxy and run a java http proxy (jhttp2.sourceforge.net/‎) on my remote machine and use ssh -L port:localhost:port to forward the port to the remote machine and use that http proxy.

Highroad answered 8/4, 2014 at 15:48 Comment(0)
Z
0

first of all you can try install proxychains-ng using

brew install proxychains-ng

the can try make a socks5 proxy using ssh -D like

ssh -D 12345 -fqN root@[your-vps-ip]

and use public-key or password to access your vps

then you have both proxychain and socks5.

Now edit /etc/proxychains.conf, simply add this line at the end of it

socks5  127.0.0.1 12345

and comment this

socks4  127.0.0.1 9050

Finally

proxychains4 pip install [whateveryouwant]
Zobias answered 31/7, 2018 at 6:59 Comment(0)
A
0

On Windows (mine was Win2012R2) I managed connecting through SOCKS5-proxy by doing those steps:

All-user-level-pip:

  1. Adding this lines to pip.ini under "C:\ProgramData\pip":

    [global]  
    proxy = socks5:{proxy-ip}:{proxy-port}
    
  2. Opening cmd.exe (maybe but not necessarily as administrator ... depends on your file-system configuration...) Setting proxy variables to "no-proxy" explicitly!!! ... like that:

    set http_proxy=no-proxy  
    set https_proxy=no-proxy
    
  3. running for example pip install your_module and finally it works through the socks5-proxy specified in the pip.ini

For user-level-pip you need to place the pip.ini somewhere else according pip-documentation.

Aweless answered 17/9, 2021 at 8:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.