问题描述
我设法创建了一个在Windows函数运行时1.x上使用numpy的python函数. /span> 自Azure Functions 2.x开始 Windows上的python支持被删除,我想在linux上实现相同的功能.
I managed to create a python function that uses numpy on the windows functions runtime 1.x. Since in Azure Functions 2.x the python support on windows was dropped, I wanted to achieve the same thing on linux.
- 通过bash,我安装了numpy以及其他一些3 rd/sup.使用命令' pip install --user<包名称>
- Via bash I installed numpy as well as some other 3<sup>rd</sup> party packages using the command 'pip install --user <name of the package>
- 我可以导入任何3< sup> rd</sup>派对python包成功但numpy.使用numpy我不断收到错误消息 在linux函数应用2.x中运行此代码时,显示以下信息:
- I can import any 3<sup>rd</sup> party python packages successfully but numpy. With numpy I keep getting the error message below when running this code in a linux function app 2.x:
尝试 :
try:
import sys
import sys
sys.path.append( '/home/. local/lib/python3.7/site-packages' )
sys.path.append('/home/.local/lib/python3.7/site-packages')
import numpy
import numpy
除外 ImportError as e:
except ImportErroras e:
logging.error( str (e))
logging.error(str(e))
导入多数组numpy扩展模块失败. 很可能您正在尝试导入失败的numpy版本.如果您使用的是numpy的git仓库,请尝试git clean -xdf(删除不受版本控制的所有文件). 否则,请重新安装numpy."
"Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes allfiles not under version control). Otherwise reinstall numpy."
当我通过bash访问功能应用并运行代码时 python3.7 -c'import numpy' 不会引发错误.
When I access the function app via bash and run the codepython3.7 -c 'import numpy' no error is thrown.
我在github上碰到了一个帖子(无法发布链接,抱歉),其中提到在配置wsgi时mod_wsgi和numpy不能很好地工作 使用子解释器.
I came across a post on github (cannot post links sorry) which mentions that mod_wsgi and numpy don't work well when wsgi is configured to use subinterpreters.
我想知道这是否也可能是Azure Functions中错误的原因,并且是否可以通过某种方式更改配置以使其可以.
推荐答案
您是否在根目录中包含了requirements.txt文件?在那里指定numpy应该可以工作.
Are you including a requirements.txt file at root? Specifying numpy there should work.
这篇关于无法在Azure Functions 2.x(Python)中导入numpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!