Closed svickers closed 9 months ago
Hi @svickers pls try again its working fine as I tested the step you provided.
@bhagyshricompany Did you add import pyodbc
to the top of the function_app.py file?
yes as you can see here.
Interesting... I pushed a basic test repo up here: https://github.com/svickers/python_test_func
Here is my environment information:
func start
Found Python version 3.10.11 (python3).
Azure Functions Core Tools
Core Tools Version: 4.0.5198 Commit hash: N/A (64-bit)
Function Runtime Version: 4.21.1.20667
pls check your file format have and directory structure
Everything looks the same, very strange. I've tried two different projects from scratch in fresh directories and environments but no luck...not sure what else could be going on. Also referencing other libraries works fine, just pyodbc that I've had an issue with.
Also one other thing to note is I can deploy to a function app just fine until I add the pyodbc reference and then it also fails to start and fails to index any functions.... which makes me think it is more than just my local environment.
If I remove the single import pyodbc line then everything works fine in azure:
I deployed code with pyodbc its working fine.
Can you post your repo somewhere so I can try it?
you downloaded python from msstore or python.org install from python.org then try
Installed from python.org.
still not working ?
Yes still not working.
@vrdmr pls comment and validate
Tried the test repo and working for me too. Here is my func info: Found Python version 3.10.11 (py).
Azure Functions Core Tools Core Tools Version: 4.0.5198 Commit hash: N/A (64-bit) Function Runtime Version: 4.21.1.20667
Here is my local.settings.json file:
@svickers Wonder whats your local.settings.file look like and can you try the core tool version i have with a new virtual environment created?
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
Still seeing the same issue with a fresh venv, really unsure what is going on because the same code also doesn't work in azure, which shouldn't have anything to do with my local setup.
My local.settings.json file is:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
Hi, I'm having the same issue. It seems it happens only when I'm trying to run func start
and I have an active virtual enviroment, and the packages needed are only installed in the virtual enviroment.
Same issue here. Only difference is that I am using v1 python model, running with init.py. Both local environment and Azure function environment have trouble importing pyodbc.
Hi, just to follow up on this.
I tested this with this setup:
I was able to replicate the error by doing this:
python -m venv .venv
.venv/Scripts/activate
func start
From this, it looks like pyodbc has not been installed correctly.
I then tried running pip install -r requirements.txt
and it started correctly:
python -m venv .venv
.venv/Scripts/activate
pip install -r requirements.txt
func start
I also tested deploying the app from VSCode (with pyodc added in requirements.txt and imported) and that was successful.
Is this still not working correctly on your end?
I have been looking for a solution to my deployment error, and I found the error .... So, the pyodbc library works with an ODBC SQL driver. So make sure you know which driver your Azure function environment works with. If you are using Python 10, it seems to me that by default it enables a driver of the type DRIVER={ODBC Driver 17 for SQL Server} . And searching through several forums, I stopped to check the driver for my environment... and it turned out that for the version of Python 11 as the environment language, the driver is DRIVER={ODBC Driver 18 for SQL Server}.
My advice will be. First make sure you know what ODBC drivers your app has with the code drivers = pyodbc.drivers()
For local tests it works the same, the driver I used was DRIVER={SQL Server} ... My connection code was conn = pyodbc.connect( "DRIVER={ODBC Driver 18 for SQL Server};" f"SERVER=tcp:{server};" f"DATABASE={database};UID={user};" f"PWD={password};" "Encrypt=yes;" "TrustServerCertificate=no;" "Connection Timeout=30;" )
In case anyone has still problem with it. For me it turned out that I forgot to install an ODBC driver manager on my Linux (dev container) prior to installing pyodbc
.
According to the pydobc
documentation:
You should make sure you have an ODBC driver manager installed before installing pyodbc. See the docs for more information about how to do this on different Unix flavors. (On Windows, the ODBC driver manager is built-in.)
Hi - I'm having this same issue. Windows 11 Azure Functions CLI v4.0.5455 Python 3.11.9
Steps to reproduce:
Create a new folder
Using Powershell 7
func new --template "Http Trigger" --name MyHttpTrigger --worker-runtime Python
python -m venv .venv
.\.venv\scripts\Activate.ps1
pip install -r requirements.txt
pip install pyodbc
pip freeze > requirements.py
In function_app.py
add line import pyodbc
(we literally just need to import the library, we don't even do any code!)
func start
This leads to two different errors:
Error in index_function_app. Sys Path: [....loads of locations....] ,python-packages Path exists: False
Worker failed to index functions
Result: Failure Exception: ModuleNotFoundError: No module named 'pyodbc'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound
Any help would be GREATLY appreciated.
I've made a YT video showing this: https://youtu.be/dR4i41d5E8Q
Thanks!
Rich
FIXED: installed Python from Python.org. Version downloaded from Microsoft Store resulted in these issues.
https://github.com/Azure/azure-functions-core-tools/issues/3042#issuecomment-1113848949
Starting from a fresh function app with the v2 model it will stop working when you import pyodbc.
Investigative information
Repro steps
func init python_test_func --python -m V2
pip install pyodbc
app = func.FunctionApp()
@app.function_name(name="HttpTrigger1") @app.route(route="hello") def test_function(req: func.HttpRequest) -> func.HttpResponse: return func.HttpResponse("HttpTrigger1 function processed a request!")
Result: Failure Exception: ModuleNotFoundError: No module named 'pyodbc'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 338, in _handlefunctions_metadata_request fx_metadata_results = self.index_functions(function_path) File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 607, in index_functions indexed_functions = loader.index_function_app(function_path) File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 48, in call raise extend_exception_message(e, message) File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 44, in call return func(*args, **kwargs) File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\loader.py", line 151, in index_function_app imported_module = importlib.import_module(module_name) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64qbz5n2kfra8p0\lib\importlib__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\me\dev\python_test_func\function_app.py", line 2, in
import pyodbc