NameError: name 'azure' is not defined in requirements.txt file - Visual Studio Code

Kirkwood Williams 10 Reputation points
2023-10-06T03:57:18.1033333+00:00

Hello,

New to azure and trying to debug the function project I recently created is VSC. My requirements.txt file was generated after creation of the project but throwing the error 'azure' is not defined. I installed the azure functions tools and modules into the env but still no luck. My functions_app.py file is in the same root location with no error messages. Python is installed and with some google research i made sure the the environment variable was pointing to the correct version.

Error

    azure-functions
    ^^^^^
NameError: name 'azure' is not defined

azure-functions is installed

Package Version


azure-functions 1.17.0

pip 23.1.2

setuptools 65.5.0

Any help will be great!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-10-09T05:14:36.1233333+00:00

    @Kirkwood Williams Thanks for getting back. Regarding your query about the requirements.txt:

    The requirements.txt file contains the list of Python packages the system installs when it publishes to Azure. When you're ready to publish, make sure that all your publicly available dependencies are listed in the requirements.txt file.

    Note: The runtime library version is fixed by Azure, and it can't be overridden by requirements.txt. The azure-functions entry in requirements.txt is only for linting and customer awareness. More info here.

    You can simply remove the azure-functions and test your function app. See the below screenshot from my machine.

    requirements.txtUser's image

    I am able to successfully trigger the function app without any entry in the requirements.txt:

    User's image

    However, If your app has any dependencies on a few of the library packages then you can add those to the requirements.txt. Then you can use the remote build option and deploy your code to Azure. When you use remote build, dependencies that are restored on the server and native dependencies match the production environment. This results in a smaller deployment package to upload. Use remote build when you're developing Python apps on Windows.

    Dependencies are obtained remotely based on the contents of the requirements.txt file. Remote build is the recommended build method. By default, Core Tools requests a remote build when you use the following func azure functionapp publish command to publish your Python project to Azure.

    func azure functionapp publish <APP_NAME>

    Hope this helps.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.