Skip to content

Unable to import local module for the last few days #577

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
dxkaufman opened this issue Nov 15, 2019 · 10 comments
Closed

Unable to import local module for the last few days #577

dxkaufman opened this issue Nov 15, 2019 · 10 comments
Assignees
Labels

Comments

@dxkaufman
Copy link

dxkaufman commented Nov 15, 2019

Environment data

  • VS Code version: 1.40.0
  • VSC python extension version: 2019.10.44104
  • OS and version: macOS 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.5 (not sure of distribution)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv (I think)
  • Relevant/affected Python packages and their versions: XXX
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): python.jediEnabled not present

Other extensions:
Azure Account 0.8.7
Azure App Service 0.16.1
Azure Functions 0.20.0
Azure Storage 0.7.2
Azure Storage Explorer 0.1.2
Git History 0.4.6
SQL Server (mssql) 1.7.0

pip freeze output at the very end of the ticket.

I appear to have azure functions core tools 2.7.1846 installed (and brew outdated doesn't list it as needing to be updated)

Expected behaviour

Code should execute while Azure attached. I also filed this in Stack Overflow the other day, as well as a ticket with Azure support - I'm stuck in the water and can't finalize my testing and upload to my production services. https://stackoverflow.com/questions/58842695/vscode-running-python-azure-function-locally-fails-with-modulenotfounderror I apologize if this isn't the right place for this post...

To be clear, this was working a couple of weeks ago. I can see, for example, that the entire data pipeline process ran successfully in my dev environment (i.e. in VSC on my desktop) on the morning of Thursday October 31, and I have literally not changed anything about my code since then, particularly with respect to the directory structure and module names.

Actual behaviour

On timer trigger or https trigger, while Azure attached, I receive this error message:

[11/14/19 5:38:07 PM] Executed 'Functions.DataPipeline' (Failed, Id=fcdcceb2-d82f-46a6-8f9f-7f0c0d82789b)
[11/14/19 5:38:07 PM] System.Private.CoreLib: Exception while executing function: Functions.DataPipeline. System.Private.CoreLib: Result: Failure
[11/14/19 5:38:07 PM] Exception: ModuleNotFoundError: No module named 'SharedCode'
[11/14/19 5:38:07 PM] Stack: File '/usr/local/Cellar/azure-functions-core-tools/2.7.1846/workers/python/3.6/OSX/X64/azure_functions_worker/dispatcher.py', line 242, in _handle__function_load_request
[11/14/19 5:38:07 PM] func_request.metadata.entry_point)
[11/14/19 5:38:07 PM] File '/usr/local/Cellar/azure-functions-core-tools/2.7.1846/workers/python/3.6/OSX/X64/azure_functions_worker/loader.py', line 66, in load_function
[11/14/19 5:38:07 PM] mod = importlib.import_module(fullmodname)
[11/14/19 5:38:07 PM] File '/Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/env/lib/python3.6/importlib/__init__.py', line 126, in import_module
[11/14/19 5:38:07 PM] return _bootstrap._gcd_import(name[level:], package, level)
[11/14/19 5:38:07 PM] File '/Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/DataPipeline/etl.py', line 6, in <module>
[11/14/19 5:38:07 PM] from SharedCode import FunctionApp
[11/14/19 5:38:07 PM] .

Steps to reproduce:

Relevant directory structure:

env
DataPipeline
   etl.py
   function.json
SharedCode
   FunctionApp.py

function.json contains the following:

{
  "scriptFile": "etl.py",
  "bindings": [
    {
      "name": "MainETL",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "45 0 * * * *",
      "_comment-test-schedule" : "*/10 * * * * *",
      "_comment-hourly-schedule" : "0 0 * * * *"
    }
  ]
}

etl.py includes the following imports:

import datetime
import logging
import azure.functions as func
import pandas as pd
import sqlalchemy
from SharedCode import FunctionApp
from SharedCode import APIs

etl.py also contains a variable & two functions that start with the same line:

functionName = "Data Pipeline"

def main(MainETL: func.TimerRequest) -> None:
    app = FunctionApp.FunctionApp(functionName, datetime.datetime.utcnow())

def Test():
    app = FunctionApp.FunctionApp(functionName, datetime.datetime.utcnow())
    print(app.functionName)

Note that function main includes a lot of other code not shown here; Test only includes the two lines above.

Function main is called when executed while Azure attached and as soon as the timer fires, it generates the ModuleNotFoundError for the first "from SharedCode" import. I created function Test to be able to test for the same problem from the command line, which works:

(env) Dylans-iMac:Data Pipeline dylankaufman$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from DataPipeline import etl
>>> etl.Test()
Data Pipeline
>>> 

Other than upgrading to VSC 1.40.0 and, I think, applying an azure core tools update, nothing has changed since I was last able to execute this properly while Azure attached.

I have also seen other posts in which the suggestion was to change the directory structure so that all the code was under an __app__ directory, but that has not helped me. I changed to this directory structure:

Data Pipeline
 | - __app__
 | | - DataPipeline
 | | | - etl.py
 | | | - function.json
 | | - SharedCode
 | | | - APIs.py
 | | | - FunctionApp.py
 | | - host.json
 | | - local.settings.json
 | - .vscode (dir)
 | - env (dir)
 | - host.json
 | - local.settings.json

Then I changed the import to from __app__.SharedCode import FunctionApp, and now I get a different problem, which is that it doesn't register the function(s):

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

I also tried looking at the pvscbot code, but I can't find anything that seems different between it and mine that would cause this. It seems as if it is not finding the function.json file any longer, once I add the app directory.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

None

Complete output in Terminal for Task - host start:

> Executing task: env/bin/python -m pip install -r requirements.txt <

Requirement already satisfied: azure-storage-blob in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (1.5.0)
Requirement already satisfied: certifi in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (2019.3.9)
Requirement already satisfied: chardet in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (3.0.4)
Requirement already satisfied: grpcio-tools==1.14.2 in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (1.14.2)
Requirement already satisfied: grpcio==1.14.2 in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (1.14.2)
Requirement already satisfied: idna in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 6)) (2.8)
Requirement already satisfied: numpy in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 7)) (1.16.2)
Requirement already satisfied: pandas in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 8)) (0.24.2)
Requirement already satisfied: protobuf==3.7.0 in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 9)) (3.7.0)
Requirement already satisfied: pycryptodome in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 10)) (3.8.1)
Requirement already satisfied: pyodbc in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 11)) (4.0.26)
Requirement already satisfied: python-dateutil in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 12)) (2.8.0)
Requirement already satisfied: pytz in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 13)) (2018.9)
Requirement already satisfied: requests in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 14)) (2.21.0)
Requirement already satisfied: six in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 15)) (1.12.0)
Requirement already satisfied: SQLAlchemy in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 16)) (1.3.2)
Requirement already satisfied: urllib3==1.24.2 in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 17)) (1.24.2)
Requirement already satisfied: gspread in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 18)) (3.1.0)
Requirement already satisfied: oauth2client in ./env/lib/python3.6/site-packages (from -r requirements.txt (line 19)) (4.1.3)
Requirement already satisfied: azure-common>=1.1.5 in ./env/lib/python3.6/site-packages (from azure-storage-blob->-r requirements.txt (line 1)) (1.1.23)
Requirement already satisfied: azure-storage-common~=1.4 in ./env/lib/python3.6/site-packages (from azure-storage-blob->-r requirements.txt (line 1)) (1.4.2)
Requirement already satisfied: setuptools in ./env/lib/python3.6/site-packages (from protobuf==3.7.0->-r requirements.txt (line 9)) (41.0.1)
Requirement already satisfied: httplib2>=0.9.1 in ./env/lib/python3.6/site-packages (from oauth2client->-r requirements.txt (line 19)) (0.13.0)
Requirement already satisfied: pyasn1-modules>=0.0.5 in ./env/lib/python3.6/site-packages (from oauth2client->-r requirements.txt (line 19)) (0.2.5)
Requirement already satisfied: pyasn1>=0.1.7 in ./env/lib/python3.6/site-packages (from oauth2client->-r requirements.txt (line 19)) (0.4.5)
Requirement already satisfied: rsa>=3.1.4 in ./env/lib/python3.6/site-packages (from oauth2client->-r requirements.txt (line 19)) (4.0)
Requirement already satisfied: cryptography in ./env/lib/python3.6/site-packages (from azure-storage-common~=1.4->azure-storage-blob->-r requirements.txt (line 1)) (2.6.1)
Requirement already satisfied: asn1crypto>=0.21.0 in ./env/lib/python3.6/site-packages (from cryptography->azure-storage-common~=1.4->azure-storage-blob->-r requirements.txt (line 1)) (0.24.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in ./env/lib/python3.6/site-packages (from cryptography->azure-storage-common~=1.4->azure-storage-blob->-r requirements.txt (line 1)) (1.12.3)
Requirement already satisfied: pycparser in ./env/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography->azure-storage-common~=1.4->azure-storage-blob->-r requirements.txt (line 1)) (2.19)
source "/Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/env/bin/activate"

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

> Executing task: . env/bin/activate && func extensions install <

Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 24.09 ms for /Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/extensions.csproj.
  extensions -> /Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/bin/extensions.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.82



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

> Executing task: . env/bin/activate && func host start <

Found Python version 3.6.5 (python).

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

Azure Functions Core Tools (2.7.1846 Commit hash: 458c671341fda1c52bd46e1aa8943cb26e467830)
Function Runtime Version: 2.0.12858.0
[11/14/19 6:12:31 PM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'bb6a5f79-1e24-4984-b756-4de96f353b7e'
[11/14/19 6:12:31 PM] Reading functions metadata
[11/14/19 6:12:31 PM] 1 functions found
[11/14/19 6:12:31 PM] Loading startup extension 'AzureStorage'
[11/14/19 6:12:31 PM] Loaded extension 'AzureStorage' (3.0.4.0)
[11/14/19 6:12:31 PM] Initializing Warmup Extension.
[11/14/19 6:12:31 PM] Initializing Host. OperationId: 'bb6a5f79-1e24-4984-b756-4de96f353b7e'.
[11/14/19 6:12:31 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=bb6a5f79-1e24-4984-b756-4de96f353b7e
[11/14/19 6:12:31 PM] LoggerFilterOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "MinLevel": "None",
[11/14/19 6:12:31 PM]   "Rules": [
[11/14/19 6:12:31 PM]     {
[11/14/19 6:12:31 PM]       "ProviderName": null,
[11/14/19 6:12:31 PM]       "CategoryName": null,
[11/14/19 6:12:31 PM]       "LogLevel": null,
[11/14/19 6:12:31 PM]       "Filter": "<AddFilter>b__0"
[11/14/19 6:12:31 PM]     },
[11/14/19 6:12:31 PM]     {
[11/14/19 6:12:31 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[11/14/19 6:12:31 PM]       "CategoryName": null,
[11/14/19 6:12:31 PM]       "LogLevel": "None",
[11/14/19 6:12:31 PM]       "Filter": null
[11/14/19 6:12:31 PM]     },
[11/14/19 6:12:31 PM]     {
[11/14/19 6:12:31 PM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[11/14/19 6:12:31 PM]       "CategoryName": null,
[11/14/19 6:12:31 PM]       "LogLevel": null,
[11/14/19 6:12:31 PM]       "Filter": "<AddFilter>b__0"
[11/14/19 6:12:31 PM]     }
[11/14/19 6:12:31 PM]   ]
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] FunctionResultAggregatorOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "BatchSize": 1000,
[11/14/19 6:12:31 PM]   "FlushTimeout": "00:00:30",
[11/14/19 6:12:31 PM]   "IsEnabled": true
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] SingletonOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "LockPeriod": "00:00:15",
[11/14/19 6:12:31 PM]   "ListenerLockPeriod": "00:00:15",
[11/14/19 6:12:31 PM]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[11/14/19 6:12:31 PM]   "LockAcquisitionPollingInterval": "00:00:05",
[11/14/19 6:12:31 PM]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] QueuesOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "BatchSize": 16,
[11/14/19 6:12:31 PM]   "NewBatchThreshold": 8,
[11/14/19 6:12:31 PM]   "MaxPollingInterval": "00:00:02",
[11/14/19 6:12:31 PM]   "MaxDequeueCount": 5,
[11/14/19 6:12:31 PM]   "VisibilityTimeout": "00:00:00"
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] BlobsOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "CentralizedPoisonQueue": false
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] HttpOptions
[11/14/19 6:12:31 PM] {
[11/14/19 6:12:31 PM]   "DynamicThrottlesEnabled": false,
[11/14/19 6:12:31 PM]   "MaxConcurrentRequests": -1,
[11/14/19 6:12:31 PM]   "MaxOutstandingRequests": -1,
[11/14/19 6:12:31 PM]   "RoutePrefix": "api"
[11/14/19 6:12:31 PM] }
[11/14/19 6:12:31 PM] Starting JobHost
[11/14/19 6:12:31 PM] Starting Host (HostId=dylansimac-1683592573, InstanceId=6434be5e-93d7-4396-b3b6-18210eb5c1b3, Version=2.0.12858.0, ProcessId=1791, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[11/14/19 6:12:31 PM] Loading functions metadata
[11/14/19 6:12:31 PM] 1 functions loaded
[11/14/19 6:12:31 PM] Starting worker process:python  /Users/dylankaufman/.vscode/extensions/ms-python.python-2019.10.44104/pythonFiles/ptvsd_launcher.py --default --host 127.0.0.1 --port 9091 --wait "/usr/local/Cellar/azure-functions-core-tools/2.7.1846/workers/python/3.6/OSX/X64/worker.py" --host 127.0.0.1 --port 49342 --workerId df6ecb15-3eb4-4a36-91b0-9b2ff7ba9c8b --requestId 157838fe-6372-4275-8942-e96be7760f77 --grpcMaxMessageLength 134217728
[11/14/19 6:12:31 PM] python process with Id=1796 started
[11/14/19 6:12:31 PM] Generating 1 job function(s)
[11/14/19 6:12:32 PM] Found the following functions:
[11/14/19 6:12:32 PM] Host.Functions.DataPipeline
[11/14/19 6:12:32 PM] 
[11/14/19 6:12:32 PM] Initializing function HTTP routes
[11/14/19 6:12:32 PM] No HTTP routes mapped
[11/14/19 6:12:32 PM] 
[11/14/19 6:12:32 PM] Host initialized (204ms)
[11/14/19 6:12:32 PM] The next 5 occurrences of the 'DataPipeline' schedule (Cron: '45 12 * * * *') will be:
[11/14/19 6:12:32 PM] 11/14/2019 10:12:45-08:00 (11/14/2019 18:12:45Z)
[11/14/19 6:12:32 PM] 11/14/2019 11:12:45-08:00 (11/14/2019 19:12:45Z)
[11/14/19 6:12:32 PM] 11/14/2019 12:12:45-08:00 (11/14/2019 20:12:45Z)
[11/14/19 6:12:32 PM] 11/14/2019 13:12:45-08:00 (11/14/2019 21:12:45Z)
[11/14/19 6:12:32 PM] 11/14/2019 14:12:45-08:00 (11/14/2019 22:12:45Z)
[11/14/19 6:12:32 PM] 
[11/14/19 6:12:32 PM] Host started (661ms)
[11/14/19 6:12:32 PM] Job host started
Hosting environment: Production
Content root path: /Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline
Now listening on: http://0.0.0.0:7106
Application started. Press Ctrl+C to shut down.
[11/14/19 6:12:37 PM] Host lock lease acquired by instance ID '0000000000000000000000001F72728D'.
[11/14/19 6:12:37 PM]  INFO: Starting Azure Functions Python Worker.
[11/14/19 6:12:37 PM]  INFO: Worker ID: df6ecb15-3eb4-4a36-91b0-9b2ff7ba9c8b, Request ID: 157838fe-6372-4275-8942-e96be7760f77, Host Address: 127.0.0.1:49342
[11/14/19 6:12:37 PM]  INFO: Successfully opened gRPC channel to 127.0.0.1:49342
[11/14/19 6:12:37 PM]  INFO: Received WorkerInitRequest, request ID 157838fe-6372-4275-8942-e96be7760f77
[11/14/19 6:12:37 PM]  INFO: Received FunctionLoadRequest, request ID: 157838fe-6372-4275-8942-e96be7760f77, function ID: 606c4f57-13c0-4282-8cda-2026ab1902af
[11/14/19 6:12:45 PM] Executing 'Functions.DataPipeline' (Reason='Timer fired at 2019-11-14T10:12:45.0183320-08:00', Id=b66cfc0e-8e35-4ac3-bb47-1bf7d2058ab2)
[11/14/19 6:12:45 PM] Executed 'Functions.DataPipeline' (Failed, Id=b66cfc0e-8e35-4ac3-bb47-1bf7d2058ab2)
[11/14/19 6:12:45 PM] System.Private.CoreLib: Exception while executing function: Functions.DataPipeline. System.Private.CoreLib: Result: Failure
[11/14/19 6:12:45 PM] Exception: ModuleNotFoundError: No module named 'SharedCode'
[11/14/19 6:12:45 PM] Stack:   File "/usr/local/Cellar/azure-functions-core-tools/2.7.1846/workers/python/3.6/OSX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
[11/14/19 6:12:45 PM]     func_request.metadata.entry_point)
[11/14/19 6:12:45 PM]   File "/usr/local/Cellar/azure-functions-core-tools/2.7.1846/workers/python/3.6/OSX/X64/azure_functions_worker/loader.py", line 66, in load_function
[11/14/19 6:12:45 PM]     mod = importlib.import_module(fullmodname)
[11/14/19 6:12:45 PM]   File "/Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
[11/14/19 6:12:45 PM]     return _bootstrap._gcd_import(name[level:], package, level)
[11/14/19 6:12:45 PM]   File "/Users/dylankaufman/Documents/Projects/SuccessHacker/Data Pipeline/DataPipeline/etl.py", line 6, in <module>
[11/14/19 6:12:45 PM]     from SharedCode import FunctionApp
[11/14/19 6:12:45 PM] .

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

I don't know how to enable source map support... 

pip freeze (after I upgraded some of the azure stuff):

adal==1.2.1
asn1crypto==0.24.0
astroid==2.2.5
azure==4.0.0
azure-applicationinsights==0.1.0
azure-batch==4.1.3
azure-common==1.1.23
azure-core==1.0.0
azure-cosmosdb-nspkg==2.0.2
azure-cosmosdb-table==1.0.5
azure-datalake-store==0.0.44
azure-eventgrid==1.2.0
azure-functions==1.0.4
azure-functions-worker==1.0.1
azure-graphrbac==0.40.0
azure-keyvault==1.1.0
azure-loganalytics==0.1.0
azure-mgmt==4.0.0
azure-mgmt-advisor==1.0.1
azure-mgmt-applicationinsights==0.1.1
azure-mgmt-authorization==0.50.0
azure-mgmt-batch==5.0.1
azure-mgmt-batchai==2.0.0
azure-mgmt-billing==0.2.0
azure-mgmt-cdn==3.1.0
azure-mgmt-cognitiveservices==3.0.0
azure-mgmt-commerce==1.0.1
azure-mgmt-compute==4.6.2
azure-mgmt-consumption==2.0.0
azure-mgmt-containerinstance==1.4.1
azure-mgmt-containerregistry==2.7.0
azure-mgmt-containerservice==4.4.0
azure-mgmt-cosmosdb==0.4.1
azure-mgmt-datafactory==0.6.0
azure-mgmt-datalake-analytics==0.6.0
azure-mgmt-datalake-nspkg==3.0.1
azure-mgmt-datalake-store==0.5.0
azure-mgmt-datamigration==1.0.0
azure-mgmt-devspaces==0.1.0
azure-mgmt-devtestlabs==2.2.0
azure-mgmt-dns==2.1.0
azure-mgmt-eventgrid==1.0.0
azure-mgmt-eventhub==2.5.0
azure-mgmt-hanaonazure==0.1.1
azure-mgmt-iotcentral==0.1.0
azure-mgmt-iothub==0.5.0
azure-mgmt-iothubprovisioningservices==0.2.0
azure-mgmt-keyvault==1.1.0
azure-mgmt-loganalytics==0.2.0
azure-mgmt-logic==3.0.0
azure-mgmt-machinelearningcompute==0.4.1
azure-mgmt-managementgroups==0.1.0
azure-mgmt-managementpartner==0.1.0
azure-mgmt-maps==0.1.0
azure-mgmt-marketplaceordering==0.1.0
azure-mgmt-media==1.0.0
azure-mgmt-monitor==0.5.2
azure-mgmt-msi==0.2.0
azure-mgmt-network==2.6.0
azure-mgmt-notificationhubs==2.0.0
azure-mgmt-nspkg==3.0.2
azure-mgmt-policyinsights==0.1.0
azure-mgmt-powerbiembedded==2.0.0
azure-mgmt-rdbms==1.8.0
azure-mgmt-recoveryservices==0.3.0
azure-mgmt-recoveryservicesbackup==0.3.0
azure-mgmt-redis==5.0.0
azure-mgmt-relay==0.1.0
azure-mgmt-reservations==0.2.1
azure-mgmt-resource==2.1.0
azure-mgmt-scheduler==2.0.0
azure-mgmt-search==2.0.0
azure-mgmt-servicebus==0.5.3
azure-mgmt-servicefabric==0.2.0
azure-mgmt-signalr==0.1.1
azure-mgmt-sql==0.9.1
azure-mgmt-storage==2.0.0
azure-mgmt-subscription==0.2.0
azure-mgmt-trafficmanager==0.50.0
azure-mgmt-web==0.35.0
azure-nspkg==3.0.2
azure-servicebus==0.21.1
azure-servicefabric==6.3.0.0
azure-servicemanagement-legacy==0.20.6
azure-storage-blob==1.5.0
azure-storage-common==1.4.2
azure-storage-file==1.4.0
azure-storage-queue==1.4.0
cachetools==3.1.1
certifi==2019.3.9
cffi==1.12.3
chardet==3.0.4
cryptography==2.6.1
google-api-python-client==1.7.9
google-auth==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.3.0
grpcio==1.14.2
grpcio-tools==1.14.2
gspread==3.1.0
httplib2==0.13.0
idna==2.8
isodate==0.6.0
isort==4.3.17
lazy-object-proxy==1.3.1
mccabe==0.6.1
msrest==0.6.10
msrestazure==0.6.0
numpy==1.16.2
oauth2client==4.1.3
oauthlib==3.0.1
pandas==0.24.2
protobuf==3.7.0
ptvsd==4.2.8
pyasn1==0.4.5
pyasn1-modules==0.2.5
pycparser==2.19
pycrypto==2.6.1
pycryptodome==3.8.1
PyJWT==1.7.1
pylint==2.3.1
pyodbc==4.0.26
python-dateutil==2.8.0
pytz==2018.9
requests==2.21.0
requests-oauthlib==1.2.0
rsa==4.0
six==1.12.0
SQLAlchemy==1.3.2
typed-ast==1.3.4
uritemplate==3.0.0
urllib3==1.24.2
wrapt==1.11.1
@Hazhzeng
Copy link
Contributor

Hi @dxkaufman,

Thanks for reaching out. Seems like you're using a deprecated syntax for python import.
The folder structure is a bit off. The function app project is not a Python module, thus, we do not support from SharedCode import module.

Could you try using from __app__.SharedCode import module but keeping the old folder structure? Reference: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#folder-structure

The proper structure:

Data Pipeline
 | - DataPipeline
 | | - etl.py
 | | - function.json
 | - SharedCode
 | | - APIs.py
 | | - FunctionApp.py
 | | - host.json
 | | - local.settings.json
 | - .vscode (dir)
 | - env (dir)
 | - host.json
 | - local.settings.json

@dxkaufman
Copy link
Author

dxkaufman commented Nov 19, 2019

Hi @Hazhzeng,
If I do from __app__.SharedCode import APIs, I get a syntax error on etl.py as soon as I save the updated file:
Unable to import '__app__.SharedCode' pylint(import-error) [6,1]

I tried changing the root from Data Pipeline to DataPipeline or even sh-data-pipeline which is what I'm now calling it in my private github repo, but got the same error when I tried to refer to it using, for example, from sh-data-pipeline.SharedCode import APIs. With the hyphens in there for sh-data-pipeline, I got a syntax error; with __app__ or shdatapipeline, I get the same import error listed above (even after changing the directory name to shdatapipeline, without hyphens).

Thanks,
Dylan

@maknotavailable
Copy link

I have been seeing the same issue lately. This work around fixed it:

import sys
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, dir_path)

from . import module

for the following folder structure

FunctionApp
 | - MyFunction
 | | - main.py
 | | - module.py
 | | - function.json

However, I think this needs to be fixed on the product side -or- the documentation needs to be updated!

@dxkaufman
Copy link
Author

dxkaufman commented Nov 19, 2019

@maknotavailable, thanks for that. I saw that work-around in a few posts, but I have it in my head (right or wrong) that once the function is in Azure it won't be able to use those path functions. I did something similar to what you did, but for my directory structure:

import sys
import os
dir_path, func_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, dir_path)

from SharedCode import FunctionApp
from SharedCode import APIs

This is working locally, but I don't know for sure if it is going to work once it is in Azure. I guess I'm going to have to set up a dev app service so that I can deploy this there and make sure it works.

I agree with you, though, this needs to be fixed (and I don't really think it should be a documentation update). This was working fine on October 31, and it really doesn't seem logical to me that it wouldn't work this way, based on the directory structure I described earlier:

from SharedCode import FunctionApp
from SharedCode import APIs

At least I'm not longer dead in the water right now!

Thank you!
Dylan

@Hazhzeng
Copy link
Contributor

Thanks @maknotavailable for providing the work-around.

@dxkaufman sorry for the inconvenience, because we are currently moving towards a new folder structure to support unit testing #469 by Brett Cannon (example folder structure here).

We are actively working on a new design and a change in Core Tools to support this new folder structure. Since then, the linting should work as expected.

@dxkaufman
Copy link
Author

@Hazhzeng, any idea when that Core Tools update will be ready? Microsoft support has suggested another work-around I may try, but I have to figure out whether I think it is going to work in Azure, just as I do with the one I am using now...

@Hazhzeng
Copy link
Contributor

Hazhzeng commented Nov 21, 2019

@dxkaufman Currently we don't have an ETA on this feature.
Currently, you can mitigate the VSCode linting by using relative import
from ..SharedCode import FunctionApp.
You also need to make your SharedCode into a Python module by creating a __init__.py

@dxkaufman
Copy link
Author

@Hazhzeng ..SharedCode doesn't work because the linter sees it as relative above the top level. I think I'm going to stick with the path insert work-around for now, but I'd appreciate it if you could let me know when the new feature is ready. Is there an issue I can follow?

@Hazhzeng
Copy link
Contributor

@dxkaufman, thanks for reminding, yes the issue is here #469. Feel free to follow up or make suggestions under it.

@kulkarnisonia16
Copy link

Looks like importing module is solved now, if you have issues with linter please open another issue. Thanks!

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

No branches or pull requests

4 participants