Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to install PIP packages through a proxy?

I have RHEL 8 server which has not internet connection and the server has a jupyter notebook installed. I need to install exchangelib module there. Since the server has no any internet connection I couldn’t do that. So I started to create a proxy like below.

http_proxy  = "http://10.11.111.11:3128"
https_proxy = "https://10.11.111.11:3128"
ftp_proxy   = "ftp://10.11.111.11:3128"

proxyDict = { 
              "http"  : http_proxy, 
              "https" : https_proxy, 
              "ftp"   : ftp_proxy
            }

# setting up the URL and checking the connection by printing the status

url = 'https://www.google.lk'
page = requests.get(url, proxies=proxyDict)
print(page.status_code)
print(page.url) 

The output of the following code is as follows.

200
https://www.google.lk

So I was able to connect to internet by using that. But I couldn’t figure out how I install pip packages after that. Can anyone guide me on that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You shouldn’t use pip as a library. pip project recommends using it with subprocess call.

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'my_package'])

Then for proxy you can add the --proxy flag to it. This Stackoverflow answer shows it well. But to complete the answer, this is how it should look like,

subprocess.check_call([
    sys.executable, 
    '-m',
    'pip',
    'install',
    '--proxy',
    'http://10.11.111.11:3128',
    'my_package'
])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading