Skip to content

Visual Studio Code Mac Catalina Import Error Reason: Image Not found #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterjbrammer opened this issue May 8, 2020 · 1 comment
Closed

Comments

@peterjbrammer
Copy link

peterjbrammer commented May 8, 2020

Using VSC on Mac Catalina to build Azure functions in Python
I am using the out of the box HTTP trigger template.

I want to test using importing a module as this seems to be the issue, so trying pyodbc module.

error generated as below

Unable to import pyodbc module error listed.

I have tried numerous suggestions #577, #436, #219
Please advise:
VS Code: April 2020 Version 1.45

VSC Environment Settings:

Select Interpreter:
Python 3.7.6 64bit ('.venv':venv)
./venv/bin/python

requirements.txt contains:
azure-functions
pyodbc

init.py contains
import azure.functions as func
import logging
import pyodbc

def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

name = req.params.get('name')
if not name:
    try:
        req_body = req.get_json()
    except ValueError:
        pass
    else:
        name = req_body.get('name')

if name:
    return func.HttpResponse(f"Hello {name}!")
else:
    return func.HttpResponse(
         "Please pass a name on the query string or in the request body",
         status_code=400
    )

Error:

Executing task in folder API-ConnectSQL: .venv/bin/python -m pip install -r requirements.txt <

source /Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL/.venv/bin/activate
Requirement already satisfied: azure-functions in ./.venv/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (1.2.1)
Requirement already satisfied: pyodbc in ./.venv/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (4.0.30)

Terminal will be reused by tasks, press any key to close it.

Executing task in folder API-ConnectSQL: . .venv/bin/activate && func host start <

Found Python version 3.7.6 (python).

              %%%%%%
             %%%%%%
        @   %%%%%%    @
      @@   %%%%%%      @@
   @@@    %%%%%%%%%%%    @@@
 @@      %%%%%%%%%%        @@
   @@         %%%%       @@
     @@      %%%       @@
       @@    %%      @@
            %%
            %

Azure Functions Core Tools (3.0.2245 Commit hash: 1d094e2f3ef79b9a478a1621ea7ec3f93ac1910d)
Function Runtime Version: 3.0.13139.0
[08/05/2020 05:16:22] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[08/05/2020 05:16:22] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[08/05/2020 05:16:22] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[08/05/2020 05:16:22] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '5bd783f9-16bd-4cc5-9578-6d02ce8d1ad4'
[08/05/2020 05:16:22] Reading host configuration file '/Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL/host.json'
[08/05/2020 05:16:22] Host configuration file read:
[08/05/2020 05:16:22] {
[08/05/2020 05:16:22] "version": "2.0",
[08/05/2020 05:16:22] "extensionBundle": {
[08/05/2020 05:16:22] "id": "Microsoft.Azure.Functions.ExtensionBundle",
[08/05/2020 05:16:22] "version": "[1.*, 2.0.0)"
[08/05/2020 05:16:22] }
[08/05/2020 05:16:22] }
[08/05/2020 05:16:22] Reading functions metadata
[08/05/2020 05:16:22] 1 functions found
[08/05/2020 05:16:22] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at /var/folders/kk/v02ssd8s2539wfsg9lr11kkw0000gn/T/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle
[08/05/2020 05:16:22] Found a matching extension bundle at /var/folders/kk/v02ssd8s2539wfsg9lr11kkw0000gn/T/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.1.1
[08/05/2020 05:16:22] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[08/05/2020 05:16:23] Skipping bundle download since it already exists at path /var/folders/kk/v02ssd8s2539wfsg9lr11kkw0000gn/T/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.1.1
[08/05/2020 05:16:23] Loading Extention bundle from /var/folders/kk/v02ssd8s2539wfsg9lr11kkw0000gn/T/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.1.1
[08/05/2020 05:16:23] Initializing Warmup Extension.
[08/05/2020 05:16:23] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[08/05/2020 05:16:23] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[08/05/2020 05:16:23] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[08/05/2020 05:16:23] Initializing Host. OperationId: '5bd783f9-16bd-4cc5-9578-6d02ce8d1ad4'.
[08/05/2020 05:16:23] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=5bd783f9-16bd-4cc5-9578-6d02ce8d1ad4
[08/05/2020 05:16:23] LoggerFilterOptions
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "MinLevel": "None",
[08/05/2020 05:16:23] "Rules": [
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "ProviderName": null,
[08/05/2020 05:16:23] "CategoryName": null,
[08/05/2020 05:16:23] "LogLevel": null,
[08/05/2020 05:16:23] "Filter": "b__0"
[08/05/2020 05:16:23] },
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[08/05/2020 05:16:23] "CategoryName": null,
[08/05/2020 05:16:23] "LogLevel": "None",
[08/05/2020 05:16:23] "Filter": null
[08/05/2020 05:16:23] },
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[08/05/2020 05:16:23] "CategoryName": null,
[08/05/2020 05:16:23] "LogLevel": null,
[08/05/2020 05:16:23] "Filter": "b__0"
[08/05/2020 05:16:23] }
[08/05/2020 05:16:23] ]
[08/05/2020 05:16:23] }
[08/05/2020 05:16:23] FunctionResultAggregatorOptions
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "BatchSize": 1000,
[08/05/2020 05:16:23] "FlushTimeout": "00:00:30",
[08/05/2020 05:16:23] "IsEnabled": true
[08/05/2020 05:16:23] }
[08/05/2020 05:16:23] SingletonOptions
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "LockPeriod": "00:00:15",
[08/05/2020 05:16:23] "ListenerLockPeriod": "00:00:15",
[08/05/2020 05:16:23] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[08/05/2020 05:16:23] "LockAcquisitionPollingInterval": "00:00:05",
[08/05/2020 05:16:23] "ListenerLockRecoveryPollingInterval": "00:01:00"
[08/05/2020 05:16:23] }
[08/05/2020 05:16:23] HttpOptions
[08/05/2020 05:16:23] {
[08/05/2020 05:16:23] "DynamicThrottlesEnabled": false,
[08/05/2020 05:16:23] "MaxConcurrentRequests": -1,
[08/05/2020 05:16:23] "MaxOutstandingRequests": -1,
[08/05/2020 05:16:23] "RoutePrefix": "api"
[08/05/2020 05:16:23] }
[08/05/2020 05:16:23] Starting JobHost
[08/05/2020 05:16:23] Starting Host (HostId=petersair-524899095, InstanceId=432a4a6d-6942-43a1-9c2f-c67c31191ac5, Version=3.0.13139.0, ProcessId=8376, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[08/05/2020 05:16:23] Loading functions metadata
[08/05/2020 05:16:23] 1 functions loaded
[08/05/2020 05:16:23] Loading proxies metadata
[08/05/2020 05:16:23] Initializing Azure Function proxies
[08/05/2020 05:16:24] 0 proxies loaded
[08/05/2020 05:16:24] Starting worker process:python /Users/peterbrammer/.vscode/extensions/ms-python.python-2020.4.76186/pythonFiles/lib/python/debugpy/no_wheels/debugpy --listen 127.0.0.1:9091 --wait-for-client "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/worker.py" --host 127.0.0.1 --port 52204 --workerId 06bd0ed2-ebea-4d1b-9ff1-d9a36523456e --requestId f8d0ab48-bfc4-4832-93fa-d1a4c15b2d76 --grpcMaxMessageLength 134217728
[08/05/2020 05:16:24] python process with Id=8379 started
[08/05/2020 05:16:24] Generating 1 job function(s)
[08/05/2020 05:16:24] Found the following functions:
[08/05/2020 05:16:24] Host.Functions.Http-Query-SQL
[08/05/2020 05:16:24]
[08/05/2020 05:16:24] Initializing function HTTP routes
[08/05/2020 05:16:24] Mapped function route 'api/Http-Query-SQL' [get,post] to 'Http-Query-SQL'
[08/05/2020 05:16:24]
[08/05/2020 05:16:24] Host initialized (871ms)
[08/05/2020 05:16:24] Host started (886ms)
[08/05/2020 05:16:24] Job host started
Hosting environment: Production
Content root path: /Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

Http Functions:

    Http-Query-SQL: [GET,POST] http://localhost:7071/api/Http-Query-SQL

[08/05/2020 05:16:29] Host lock lease acquired by instance ID '000000000000000000000000F04F65BB'.
[08/05/2020 05:16:30] INFO: Starting Azure Functions Python Worker.
[08/05/2020 05:16:30] INFO: Worker ID: 06bd0ed2-ebea-4d1b-9ff1-d9a36523456e, Request ID: f8d0ab48-bfc4-4832-93fa-d1a4c15b2d76, Host Address: 127.0.0.1:52204
[08/05/2020 05:16:30] INFO: Successfully opened gRPC channel to 127.0.0.1:52204
[08/05/2020 05:16:30] INFO: Received WorkerInitRequest, request ID f8d0ab48-bfc4-4832-93fa-d1a4c15b2d76
[08/05/2020 05:16:30] INFO: Received FunctionLoadRequest, request ID: f8d0ab48-bfc4-4832-93fa-d1a4c15b2d76, function ID: 1e414182-05c4-4ca2-bd30-21f07ca6a770
[08/05/2020 05:16:30] Worker failed to function id 1e414182-05c4-4ca2-bd30-21f07ca6a770.
[08/05/2020 05:16:30] Result: Failure
[08/05/2020 05:16:30] Exception: ImportError: dlopen(/Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL/.venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
[08/05/2020 05:16:30] Referenced from: /Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL/.venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
[08/05/2020 05:16:30] Reason: image not found
[08/05/2020 05:16:30] Stack: File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
[08/05/2020 05:16:30] func_request.metadata.entry_point)
[08/05/2020 05:16:30] File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/azure_functions_worker/loader.py", line 66, in load_function
[08/05/2020 05:16:30] mod = importlib.import_module(fullmodname)
[08/05/2020 05:16:30] File "/Users/peterbrammer/opt/anaconda3/lib/python3.7/importlib/init.py", line 127, in import_module
[08/05/2020 05:16:30] return _bootstrap._gcd_import(name[level:], package, level)
[08/05/2020 05:16:30] File "", line 1006, in _gcd_import
[08/05/2020 05:16:30] File "", line 983, in _find_and_load
[08/05/2020 05:16:30] File "", line 953, in _find_and_load_unlocked
[08/05/2020 05:16:30] File "", line 219, in _call_with_frames_removed
[08/05/2020 05:16:30] File "", line 1006, in _gcd_import
[08/05/2020 05:16:30] File "", line 983, in _find_and_load
[08/05/2020 05:16:30] File "", line 967, in _find_and_load_unlocked
[08/05/2020 05:16:30] File "", line 677, in _load_unlocked
[08/05/2020 05:16:30] File "", line 728, in exec_module
[08/05/2020 05:16:30] File "", line 219, in _call_with_frames_removed
[08/05/2020 05:16:30] File "/Users/peterbrammer/Documents/development/Microsoft/Synergy/API-ConnectSQL/Http-Query-SQL/init.py", line 11, in
[08/05/2020 05:16:30] import pyodbc
[08/05/2020 05:16:30] .

@peterjbrammer
Copy link
Author

As it was a mac related issue, needed to install unixodbc
brew install unixodbc
+
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15

/usr/bin/ruby -e "$(curl -fsSL https://github.com/raw/Homebrew/install/master/install)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install [email protected] [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant