question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot import 'run' (aio_compat.py) (only fails in my local environment using VSCode)

See original GitHub issue

I have a very simple azure function that gets a parameter (please see the code at the bottom) and returns a HttpResponse, after running it it fails with:

cannot import name 'run'
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\aio_compat.py", line 84, in <module>
    from asyncio import run, get_running_loop  # NoQA
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\main.py", line 6, in <module>
    from . import aio_compat
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py", line 5, in <module>
    from azure.functions_worker.main import main

This only happens locally, the deployed function is working appropriately in the azure function service

Investigative information

Please provide the following:

  • Timestamp: 2019-07-08T19:05:00
  • Function App name: HttpTriggerFTPCheck
  • Function name(s) (as appropriate):
  • Core Tools version: win-x64.2.7.1373
  • Python version : Python 3.6.7 :: Anaconda, Inc.

Repro steps

Provide the steps required to reproduce the problem:

I only have a very simple function that gets a parameter and returns a JSON response with that parameter’s value…

  1. Debug __init__.py

It’s been working for almost one week and suddenly the following error started happening: This only happens in my local environment (PC), not the actual azure function that is deployed already. Not sure about what is going on, I’ve seen this when there are circular dependencies, but I’m not sure about this case.

Expected behavior

Provide a description of the expected behavior.

Response with:

"result": "saul"

Actual behavior

Provide a description of the actual behavior observed.

It’s been working for almost one week and suddenly the following error started happening:

cannot import name 'run'
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\aio_compat.py", line 84, in <module>
    from asyncio import run, get_running_loop  # NoQA
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\main.py", line 6, in <module>
    from . import aio_compat
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py", line 5, in <module>
    from azure.functions_worker.main import main

Known workarounds

Provide a description of any known workarounds.

Related information

Provide any related information

  • Links to source
  • Contents of the requirements.txt file
  • Bindings used
#__init__.py
import logging
import json
import azure.functions as func


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(json.dumps({'result': name}))
    else:
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",
             status_code=400
        )
azure-functions==1.0.0a4
azure-functions-worker==1.0.0a4
grpcio==1.14.2
grpcio-tools==1.14.2
protobuf==3.6.1
six==1.11.0

functions.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
marceloazambujacommented, Jun 10, 2020

Thanks, @anirudhgarg ! Your tip saved my life here! Thank you!

1reaction
anirudhgargcommented, Jun 10, 2020

This is an issue with the Python VSCode extension. Please find the workaround here till this is fixed: https://github.com/Azure/azure-functions-core-tools/issues/2026#issuecomment-642168916

Read more comments on GitHub >

github_iconTop Results From Across the Web

vscode import error for python module - Stack Overflow
I tried to add this in my launch.json , then it works! "env": {"PYTHONPATH": "${workspaceRoot}"}. below is my launch.json "name": "Python: ...
Read more >
Using Python Environments in Visual Studio Code
An "environment" in Python is the context in which a Python program runs and consists of an interpreter and any number of installed...
Read more >
Troubleshoot Terminal launch failures - Visual Studio Code
Try running your designated integrated terminal shell outside VS Code from an external terminal or command prompt.
Read more >
Get Started Tutorial for Python in Visual Studio Code
This tutorial introduces you to VS Code as a Python environment, primarily how to edit, run, and debug code through the following tasks:....
Read more >
Remote Development Tips and Tricks - Visual Studio Code
This section includes some tips and tricks for getting the Remote - SSH extension up and running in different environments. Configuring key based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found