I am running VSCode 1.40.0 upgraded very recently on macOS 10.14.6, with Python 3.6.5 in a venv. Prior to the upgrade, my code was working (week before last, the last time I did some work on it). This workspace is a set of Azure Functions, with the following launch.json configuration for running it:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start",
"logToFile": true,
}
]
}
The directory structure is:
.
-- env (python env)
-- SharedCode
---- FunctionApp.py
-- TLoginEvents
---- tlogins.py
When I run the code in VSCode, I get the following ModuleNotFoundError:
[11/13/19 5:17:08 PM] Executed 'Functions.TLoginEvents' (Failed, Id=c6e6b342-4250-4041-8d19-8ce4ae8bb736)
[11/13/19 5:17:08 PM] System.Private.CoreLib: Exception while executing function: Functions.TLoginEvents. System.Private.CoreLib: Result: Failure
[11/13/19 5:17:08 PM] Exception: ModuleNotFoundError: No module named 'SharedCode'
[11/13/19 5:17:08 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/13/19 5:17:08 PM] func_request.metadata.entry_point)
[11/13/19 5:17:08 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/13/19 5:17:08 PM] mod = importlib.import_module(fullmodname)
[11/13/19 5:17:08 PM] File "/Users/dylankaufman/Documents/Projects/SH/Data Pipeline/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
[11/13/19 5:17:08 PM] return _bootstrap._gcd_import(name[level:], package, level)
[11/13/19 5:17:08 PM] File "/Users/dylankaufman/Documents/Projects/SH/Azure Functions/TLoginEvents/tlogins.py", line 1, in <module>
[11/13/19 5:17:08 PM] from SharedCode import FunctionApp
[11/13/19 5:17:08 PM] .
Though I never noticed it before, I do find it quite curious that the stack trace seems to be looking into the env for a different project (Data Pipeline) than the one I'm actually running. The current project (Azure Functions) was created by copying the original directory wholesale, but I thought the whole point of the env was that it was local... (I'm still relatively new to Python & VSCode, so if anyone can explain that one, or point me at something that does, I'd appreciate it).
That said, I don't think that's really the issue. If I run python3 in the same env in the Terminal window (even inside VSCode), I can run the import just fine, like so (this is in a stand-alone terminal window):
Dylans-iMac:Azure Functions dylankaufman$ source ./env/bin/activate
(env) Dylans-iMac:Azure Functions 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 SharedCode import FunctionApp
>>> import datetime
>>> app = FunctionApp.FunctionApp('test', datetime.datetime.utcnow())
>>> app.functionName
'test'
>>>
In case it is useful, here is the vscode settings.json:
{
"python.pythonPath": "${workspacefolder}/env/bin/python",
"azureFunctions.projectRuntime": "~2",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.templateFilter": "Verified",
"azureFunctions.deploySubpath": "Azure Functions.zip",
"azureFunctions.preDeployTask": "func: pack --build-native-deps",
"files.exclude": {
"obj": true,
"bin": true
},
"azureFunctions.pythonVenv": "env",
"debug.internalConsoleOptions": "neverOpen"
}
(note that I added ${workspacefolder} today as part of troubleshooting this, to no avail)
Thank you for any help/insight you can provide!
Dylan