Python site-packages in Azure (Python) WebJobs
Using site-packages in Python environment is a natural way to code - You are probably not including any Python package as subdirectory in Your project because it is hard to maintain and project bundle could have an enormous size. On Azure Web App platform we have a huge set of site-packages as I mentioned here.
The use of site-packages is very simple but not obvious. It's because of the fact that site-packages are not in venv and we need to append site-packages path to our venv PATH.
For example, if we want to use requests in our WebJob we can't just import it:
import requests
import time
def ping():
url = 'http://yourapp.azurewebsites.net/'
r = requests.get(url)
print 'OK'
while True:
ping()
time.sleep(180)
Appending site-packages is simple:
import sys
sitepackage = "D:\home\site\wwwroot\env\Lib\site-packages"
sys.path.append(sitepackage)
And together it will look like this:
import sys
sitepackage = "D:\home\site\wwwroot\env\Lib\site-packages"
sys.path.append(sitepackage)
import requests
import time
def ping():
url = 'http://yourapp.azurewebsites.net/'
r = requests.get(url)
print 'OK'
while True:
ping()
time.sleep(180)