【问题标题】:When deploying python Azure function on azure get No module found error在azure上部署python Azure函数时get No module found错误
【发布时间】:2019-08-03 01:19:40
【问题描述】:

我创建了一个也在本地执行的 Python Azure HttpTrigger 函数。它在本地运行良好,但是当我在 azure 上部署 Azure HttpTrigger 函数时,出现以下错误:-

There was an error restoring dependencies. ERROR: cannot install pyodbc-4.0.25 dependency: binary dependencies without wheels are not supported. 
Use the --build-native-deps option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish

我在requirement.txt file 中添加了 Pyodbc 包。当 python azure 函数部署在 azure 上时,pyodbc 安装在本地 python 路径而不是 .env 路径中。

我已经选择了python解释器\.env\Scripts\python.ext,但是pyodbc包安装在本地python路径上。

我无法理解如何解决上述问题?如果有人知道解决方案,请告诉我。我想在 azure funcions 上安装包。

【问题讨论】:

  • 尝试在 Github 中发布 Azure 功能 - github.com/azure/azure-functions/issues
  • 请参考这个issue
  • @GeorgeChen 我已经尝试过了,但是没有用。是任何其他解决方案。
  • @GeorgeChen 每当我在 python azure 函数中使用外部包时,我就遇到了部署错误。

标签: python azure azure-functions


【解决方案1】:

我想您对如何在 Azure 函数应用中安装和使用 Python 第三方模块感到困惑。你可以参考我的工作步骤。

第一步:

导航到您的函数应用 kudu url:https://Your_APP_NAME.scm.azurewebsites.net/DebugConsole

d:/home/site/wwwroot/<your function name> 文件夹中运行以下命令(需要一些时间)

python -m virtualenv myvenv

第 2 步:

通过env/Scripts文件夹中的以下命令加载环境。

activate.bat

第 3 步:

您的 shell 现在应该以 (env) 为前缀。

更新点子

python -m pip install -U pip

安装你需要的东西

python -m pip install MySQLdb <pyodbc>

第四步:

在您的代码中,更新 sys.path 以添加此 venv:

import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'env/Lib/site-packages')))

然后通过下面代码的sn-p连接mysql db

#!/usr/bin/python
import MySQLdb

# Connect
db = MySQLdb.connect(host="localhost",
                     user="appuser",
                     passwd="",
                     db="onco")

cursor = db.cursor()

# Execute SQL select statement
cursor.execute("SELECT * FROM location")

# Commit your changes if writing
# In this case, we are only reading data
# db.commit()

# Get the number of rows in the resultset
numrows = cursor.rowcount

# Get and display one row at a time
for x in range(0, numrows):
    row = cursor.fetchone()
    print row[0], "-->", row[1]

# Close the connection
db.close()

另外,你也可以参考我之前的案例:Import module into Python Azure Function

【讨论】:

    猜你喜欢
    • 2018-08-09
    • 2021-03-04
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多