1

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?

veganbu chat
  • 106
  • 11
  • Are you trying to use `pip` module in your own python code, or are you using command-line `pip` executable? – alani Nov 28 '21 at 17:31
  • @alani I have used pip Install exchangelib code at the begining of the script.But there was an error called module not found. – veganbu chat Nov 28 '21 at 17:33

1 Answers1

2

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'
])
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187