When building and deploying my python functions using Github workflow, the functions build using oryx. The virtual environment in oryx gets set up in the pythonenv3.8 folder (see logs below). But at runtime, I'm getting an error "Failure Exception: ModuleNotFoundError: No module named 'requests'". I believe the Static Web Apps functions expect the virtual environment to be in the .venv folder, not the pythonenv3.8 folder.
There are two solutions to this problem that I can think of: (1) change oryx to install packages to an expected folder, or (2) search for packages in pythonenv* when running functions.
Downloading and extracting 'python' version '3.8.6' to '/tmp/oryx/platforms/python/3.8.6'...
Downloaded in 2 sec(s).
Verifying checksum...
Extracting contents...
Done in 4 sec(s).
Python Version: /tmp/oryx/platforms/python/3.8.6/bin/python3.8
Python Virtual Environment: pythonenv3.8
Creating virtual environment...
Activating virtual environment...
Running pip install...
[04:44:20+0000] Collecting azure-functions
[04:44:20+0000] Downloading azure_functions-1.5.0-py3-none-any.whl (124 kB)
[04:44:21+0000] Collecting requests==2.25.0
[04:44:21+0000] Downloading requests-2.25.0-py2.py3-none-any.whl (61 kB)
[04:44:21+0000] Collecting idna<3,>=2.5
[04:44:21+0000] Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
[04:44:21+0000] Collecting chardet<4,>=3.0.2
[04:44:21+0000] Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
[04:44:21+0000] Collecting urllib3<1.27,>=1.21.1
[04:44:21+0000] Downloading urllib3-1.26.2-py2.py3-none-any.whl (136 kB)
[04:44:21+0000] Collecting certifi>=2017.4.17
[04:44:21+0000] Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
[04:44:21+0000] Installing collected packages: azure-functions, idna, chardet, urllib3, certifi, requests
[04:44:22+0000] Successfully installed azure-functions-1.5.0 certifi-2020.12.5 chardet-3.0.4 idna-2.10 requests-2.25.0 urllib3-1.26.2
WARNING: You are using pip version 20.2.1; however, version 20.3.1 is available.
You should consider upgrading via the '/github/workspace/api/pythonenv3.8/bin/python -m pip install --upgrade pip' command.
Preparing output...
Copying files to destination directory '/bin/staticsites/ss-oryx/api'...
Done in 0 sec(s).
Looks like we're currently not installing Python packages to a location that the Functions Python worker is expecting (.python_packages/lib/site-packages). We'll need to change the Static Web Apps action or Oryx to use the correct path.
In the meantime, as a workaround until this is fixed, you can add a step before the Static Web Apps action to install packages into the right place. See this commit for an example.
I will take a look at it ... @molson194 by any chance do you have any hardcoded dependency in your code/config where you are referring .venv as path or something?
@arroyc Nothing hardcoded. Take a look at this repro that simply pulls in requests and uses it in the httptrigger function. https://github.com/anthonychu/20201210-test-python-swa
Most helpful comment
Looks like we're currently not installing Python packages to a location that the Functions Python worker is expecting (
.python_packages/lib/site-packages). We'll need to change the Static Web Apps action or Oryx to use the correct path.In the meantime, as a workaround until this is fixed, you can add a step before the Static Web Apps action to install packages into the right place. See this commit for an example.