简体   繁体   English

在Azure上的Python WebJob中导入Numpy

[英]Import Numpy in Python WebJob on Azure

How do I add Numpy (and other requirements) to a Python WebJob on Microsoft Azure? 如何在Microsoft Azure上将Numpy(和其他要求)添加到Python WebJob?

I have deployed a Python WebJob on Azure, and was able to import packages by copying them manually from my local system to a folder site-packages and calling sys.path.append('site-packages') , as explained in this post . 我已经在Azure上部署了Python WebJob,并且能够通过将软件包从本地系统手动复制到本地site-packages并调用sys.path.append('site-packages')来导入软件包, 如本博文所述 This works fine for some packages, but not for numpy. 这对于某些软件包很好,但对于numpy则不行。

When trying to import numpy, I get this error: 尝试导入numpy时,出现以下错误:

File "site-packages\\numpy\\core\\__init__.py", line 14, in <module> from . import multiarray ImportError: cannot import name 'multiarray'

I have tried using the numpy folder from my Mac running python 3.5, and from a Windows PC running python 3.4. 我尝试从运行python 3.5的Mac和运行python 3.4的Windows PC中使用numpy文件夹。 The Azure WebJob is running python 3.4. Azure WebJob正在运行python 3.4。

Ideally I would like to put a requirements.txt somewhere, but this doesn't seem to work with Azure WebJobs. 理想情况下,我想将requirements.txt放在某处,但这似乎不适用于Azure WebJobs。

I found that you need to have the full path for the site-packages folder. 我发现您需要具有site-packages文件夹的完整路径。

import sys, os
sys.path.append(os.path.join(os.getcwd(), "site-packages"))
import numpy as np

a = np.arange(15).reshape(3, 5)

print "%r" % a

also since numpy contains some C++ dlls, make sure you copied it from a Windows machine. 另外,由于numpy包含一些C ++ dll,因此请确保您从Windows计算机复制了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM