在Azure上部署python Azure函数时未找到模块错误
我已经创建了一个Python Azure HttpTrigger函数,该函数也在本地服务器上执行。它在本地上运行良好,但当我在Azure上部署Azure HttpTrigger函数时,出现以下错误:-在Azure上部署python Azure函数时未找到模块错误,python,azure,azure-functions,Python,Azure,Azure Functions,我已经创建了一个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
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文件
中添加了Pyodbc包。当python azure函数部署在azure上时,pyodbc安装在本地python路径而不是.env路径中
我已经选择了python解释器\.env\Scripts\python.ext
,但是pyodbc包安装在本地python路径上
我无法理解如何解决上述问题?如果有人知道解决办法,请告诉我。我想在azure Functions上安装软件包。我想您可能对如何在azure function应用程序中安装和使用Python第三方模块感到困惑。你可以参考我的工作步骤 步骤1: 导航到您的功能应用程序kudu url:
https://Your_APP_NAME.scm.azurewebsites.net/DebugConsole
在d:/home/site/wwwroot/
文件夹中运行下面的命令(需要一些时间)
步骤2:
通过env/Scripts
文件夹中的以下命令加载env
activate.bat
步骤3:
您的shell现在应该以(env)作为前缀
更新pip
python -m pip install -U pip
安装你需要的东西
python -m pip install MySQLdb <pyodbc>
然后通过下面的代码片段连接到mysql数据库
#!/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()
此外,您还可以参考我以前的案例: 尝试将其发布到Github for Azure函数中-请参考此内容。@GeorgeChen我已经尝试过了,但没有成功。是任何其他解决方案。@geogechen每当我在pythonazure函数中使用外部包时,就会出现部署错误。
import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'env/Lib/site-packages')))
#!/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()