1

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.

4
  • Try posting it in Github for Azure functions - github.com/azure/azure-functions/issues Commented Jul 26, 2019 at 3:24
  • Please refer to this issue. Commented Jul 26, 2019 at 5:54
  • @GeorgeChen I have already tried it, but it didn't work. Is the any other solution. Commented Jul 26, 2019 at 7:18
  • @GeorgeChen whenever i am used external package in python azure functions then that time i got deployment error. Commented Jul 26, 2019 at 10:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.