Python中的Azure WebJob:如何访问Azure Python包?
我有一个用Python编写的简单Azure WebJob,它利用了Azure Python包(位于我的解决方案中的venv中)。作业在我的本地计算机上按预期执行,但当我将其部署到Azure WebJob实例时,出现以下错误: ImportError:没有名为azure.storage.table的模块 实际的.py如下所示:Python中的Azure WebJob:如何访问Azure Python包?,python,azure,azure-webjobs,azure-table-storage,Python,Azure,Azure Webjobs,Azure Table Storage,我有一个用Python编写的简单Azure WebJob,它利用了Azure Python包(位于我的解决方案中的venv中)。作业在我的本地计算机上按预期执行,但当我将其部署到Azure WebJob实例时,出现以下错误: ImportError:没有名为azure.storage.table的模块 实际的.py如下所示: from azure.storage.table import TableService # get table service table_service = Tabl
from azure.storage.table import TableService
# get table service
table_service = TableService(account_name='myacct', account_key='mykey')
# delete table
table_service.delete_table('MyTable')
如何从WebJob实例访问azure软件包?我目前找到的唯一解决方案是自己推送软件包。这可能会帮助您:
默认情况下,如果在Azure Web app上的python应用程序中使用
venv
,则在将Web app部署到Azure后,venv
文件夹将位于D:\home\site\wwwroot\env\
中。python库也将位于D:\home\site\wwwroot\env\Lib\site packages
。您可以在web应用程序中安装python LIB,并在python web作业脚本中利用此绝对地址,在python web应用程序中加载LIB
请在WebJobs中尝试以下测试脚本:
import sys
sitepackage = "D:\home\site\wwwroot\env\Lib\site-packages"
sys.path.append(sitepackage)
try:
from azure.storage.table import TableService
print "successfully load lib"
except ImportError, e:
print "cannot load lib"
底层web应用程序是ASP.NET WebApi。我假设您的答案只适用于Azure中基于Python的web应用程序。即使您只在webjob中使用Python env,总体思路也是一样的。您可以使用您的Lib(类似于)生成python环境,并使用python webjob脚本打包
env
,将sitepackage
修改为相对路径,即env\Lib\site packages
,并一起删除到Azure WebJobs。该链接不再有效