我有一个简单的用Python编写的Azure WebJob,它利用了Azure python包(位于我的解决方案中的venv中)。作业在本地计算机上按预期执行,但是当我将其部署到Azure WebJob实例时,出现以下错误:
ImportError:没有名为azure.storage.table的模块
实际的.py如下所示:
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程序包?
默认情况下,如果您利用venv
Azure Web应用程序上的python应用程序,则在将Web应用程序部署到Azure之后,该venv
文件夹将位于中D:\home\site\wwwroot\env\
。python库也位于D:\home\site\wwwroot\env\Lib\site-packages
。您可以在Web应用程序中安装python库,并在python Web作业脚本中利用此绝对地址,以将libs加载到python Web应用程序中。
请在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"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句