1
votes

I have created a Python Azure HttpTrigger function also executed on the local. It works fine on local but when I am deploying Azure HttpTrigger function on azure then I got below error:-

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

I have added the Pyodbc package in requirement.txt file. When python azure functions deploying on azure that time pyodbc installed on the local python path not in .env path.

I have already selected the python interpreter \.env\Scripts\python.ext but pyodbc package installs on the local python path.

I am not able to understand how can I solve above problem? If anybody knows the solution please let me know. I want to install packages on azure funcions.

1
Try posting it in Github for Azure functions - github.com/azure/azure-functions/issuesSilly John
Please refer to this issue.George Chen
@GeorgeChen I have already tried it, but it didn't work. Is the any other solution.Akshay Godase
@GeorgeChen whenever i am used external package in python azure functions then that time i got deployment error.Akshay Godase

1 Answers

1
votes

I suppose that you confused about how to install and use Python third-party module in the Azure function app. You could refer to my working steps.

Step 1 :

Navigate to your function app kudu url : https://Your_APP_NAME.scm.azurewebsites.net/DebugConsole.

Run below command in d:/home/site/wwwroot/<your function name> folder (will take some time)

python -m virtualenv myvenv

Step 2 :

Load the env via the below command in env/Scripts folder.

activate.bat

Step 3 :

Your shell should be now prefixed by (env).

Update pip

python -m pip install -U pip

Install what you need

python -m pip install MySQLdb <pyodbc>

Step 4 :

In your code, update the sys.path to add this venv:

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

Then connect to mysql db via the snippet of code below

#!/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()

In addition, you could also refer to my previous case: Import module into Python Azure Function.