JrtPec
JrtPec

Reputation: 321

Import Numpy in Python WebJob on Azure

How do I add Numpy (and other requirements) to a Python WebJob on Microsoft Azure?

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. This works fine for some packages, but not for numpy.

When trying to import numpy, I get this error:

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. The Azure WebJob is running python 3.4.

Ideally I would like to put a requirements.txt somewhere, but this doesn't seem to work with Azure WebJobs.

Upvotes: 1

Views: 1531

Answers (1)

ahmelsayed
ahmelsayed

Reputation: 7402

I found that you need to have the full path for the site-packages folder.

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.

Upvotes: 4

Related Questions