SSH into WebApp: How to get correct Python environment?

Thomas Kastl 1 Reputation point
2021-02-15T12:36:28.21+00:00

I am deploying my WebApp via git. I am then trying to access my installed libraries via SSH, but cannot find them.

When pushing to the server, as expected, it tells me that it is using a virtual enviroment and installing my requirements.txt there, e.g.

remote: Python Virtual Environment: antenv
remote: Creating virtual environment...
...~
remote: [11:33:35+0000] Collecting azure-datalake-store>=0.0.50
remote: [11:33:35+0000]   Using cached azure_datalake_store-0.0.51-py2.py3-none-any.whl (53 kB)

However, I want to do some additional setup in the startup.sh script I have. The problem is, I cannot find the Python environment when I connect via SSH. If I do

which python3

It tells me /opt/python/3/bin/python3

I tried activating the antenv like this:

activate /antenv/bin/activate

But that doesn't seem to make a difference. When I run python3 and try to import my library, it is not installed, meaning I am in the wrong venv.

How do I access the correct one from SSH?

ls /antenv/lib/python3.8/site-packages/ shows the azure package, so it looks like it is installed...

Edit: I just noticed that when I start the SSH window, it tells me

-bash: antenv/bin/activate: No such file or directory

I guess my build is broken in some way?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,132 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 23,476 Reputation points Microsoft Employee
    2021-02-16T14:52:12.287+00:00

    @Thomas Kastl , It looks like you’re using Web App for Containers, it uses your own Docker container, so the stack is integrated. To better assist you on this, are you deploying any specific azure-datalake template?

    The App Service deployment engine automatically activates a virtual environment and runs pip install -r requirements.txt for you when you deploy a Git repository, or a zip package. How exactly are you provisioning the WebApp?

    On App Servvice, Oryx running in the Build Agent installs the dependencies listed in requirements.txt into a virtual environment named antenv. This build is carried out in a local build directory. This virtual environment produced by the above build is compressed and extracted by the runtime at the root of the container to enable the users to have an optimal build and startup time.

    Kindly check this Python Build Changes for details.


  2. Oliver Chapple 0 Reputation points
    2023-10-08T21:30:18.2766667+00:00

    If you use the Azure App Service code deployment, then it sets up the build and deployment process and templates to do so. It appears if you have a local virtual environment installed in Visual Code and named it venv then your Azure App Service build process will install the virtual environment as you have named it in vc e.g. venv.

    However, the Azure App Service deployment part of the process after build, looks specifically for a virtual environment called antenv. So I believe the only way to resolve this undocumented complication and potential issue, is to change the .yaml workflow file and rename the virtual environment there to antenv with all associated references in that file.

    0 comments No comments