Repository navigation
Description
The current AddPythonApp methods have a few usability issues:
-
When it was renamed from
AddPythonProject, theprojectDirectoryparameter wasn't renamed toappDirectory -
The two overloads both have only
stringparameters and finish with aparams string[]parameter, which means the compiler can't differentiate between them unless theparamsarg is passed as astring[]. Trying to call the overload with the shorter parameter count with at least one argument for theparamsparameter, results in the compiler binding to the overload with the longer parameter count:// What I want to type to call './PythonApp/main.py arg1 arg2' builder.AddPythonApp("python-app", "../PythonApp", "main.py", "arg1", "arg2"); // This actually binds to the overload that accepts the location of the virtual environment directory, so this is actually what happens. // This results in a runtime exception as the python resource verifies the specified virtual environment path exists and throws if not. builder.AddPythonApp(name: "python-app", projectDirectory: "./PythonApp", scriptPath: "main.py", virtualEnvironmentPath: "arg1", "arg2"); // This is the workaround builder.AddPythonApp("python-app", "../PythonApp", "main.py", ["arg1", "arg2"]);
-
There's no first-class overload or different method to support running python apps where a module is the entrypoint and figuring out how to invoke the overloads that are there such that a module is used as the entrypoint is confusing due to the parameter counts and names. When combined with the previous point, this is what is required to run a Python app using a module as the entrypoint:
// You need to pass "-m" as the value for the 'scriptPath' parameter: builder.AddPythonApp("python-app-module", "../PythonApp", scriptPath: "-m", ["module-name", "moduleArg1"]);
-
The integration requires the use of Python virtual environments, but not all Python apps use them. Some apps use no virtual environments, others use virtual environments managed by a different toolchain like Miniconda. Furthermore, the virtual environment is not created or activated automatically by the integration. As the recommendation is to not include the virtual environment directory in source control, the user must manually create and activate the virtual environment, and install dependencies into it, before launching the app host project, after cloning or cleaning their local clone. We should consider:
- Supporting Python apps that don't use virtual environments or use virtual environments and/or package managers other than Pip
- Doing more to automate bootstrapping virtual environments for apps that use them
-
Similar to the point above about running a Python app where a module is the entry point, some Python apps use a completely different executable as the entry point, i.e., something other than
python. Indeed on Ubuntu and other distros the default python command ispython3, notpython. Frameworks like Flask have their own command, i.e.,flask. -
PythonAppResourceis in the namespaceAspire.Hosting.Python, whereasNodeAppResourceis directly inAspire.Hosting. This is inconsistent, we should putPythonAppResourceinAspire.Hosting.

Activity
joperezr commentedon Oct 14, 2024
Discussed this offline. We should try to minimize the changes that go into 9.0 at this point, so if there are issues with the new API, we should consider marking it as experimental so we get more bake time.
raffaeler commentedon Oct 17, 2024
Please consider also the case where the python application fails to run and the console output is completely empty.
There is also no output in the output AppHost output window.
Anyway, the same command line used by Aspire, can run successfully when running it from the command prompt.
I would expect catching the stdout+stderr to the Console window as well.
DamianEdwards commentedon Oct 17, 2024
Hmm I didn't see that particular issue, but note I was using Aspire 9 bits. I definitely saw error logs from the failing Python app in the console logs of the Python resource.
raffaeler commentedon Oct 17, 2024
It looks like that when the Python process fails prematurely, the Console does not show anything.
I tried to put a print at the very beginning but nothing.
I only see a mysterious exit with error code 1
DamianEdwards commentedon Oct 17, 2024
How prematurely? Can you share a minimal repro, preferably as a GitHub repo?
raffaeler commentedon Oct 17, 2024
The Python code is ok as I can launch it on the cmd.
It also works correctly using .AddDockerfile.
I tried reducing the code to the sample Python code shown in AddPythonProject docs which uses flask to listen on 8111.
While I may have something wrong with the solution, the real issue is the inability to diagnose a failure when launching it.
I can only see a socket exception in the AppHost output window which does not provide any clue.
I will try tomorrow (now it's night here) to create a new solution in a public repo.
raffaeler commentedon Oct 17, 2024
It immediately exit at launch time. I suspect it is so fast that the Aspire console is unable to capture the Python exit message (if any).
The other suspect is that it fails running the process completely but there is no message suggesting it
raffaeler commentedon Oct 23, 2024
Damian Edwards (@DamianEdwards) sorry for the delay but I wanted to test the scenario on Aspire9 first:
https://github.com/raffaeler/aspire9tests
The issue is still there on the newest bits. It's worth noting:
AddPythonProjecttoAddPythonApp.AddDockerfilesuccessfully creates the container (inside it runs ok) but it looks inaccessible from the host machine. On Aspire 8 the.AddDockerfileworks correctlyhttpprofile, but be aware that I created and installed my own localhost certificate chain (not needed in this repro, but it is in the real project). May this be the culprit even if I am on thehttpprofile?What is disturbing is the difficulty in diagnosing what's going wrong.
What's the best way to diagnose the issue here?
Thanks
21 remaining items
karolz-ms commentedon Dec 19, 2024
Sorry for taking so long to look into this. My teammate (Devin Breshears (@dbreshears)) was able to get the example running after a few tries, but we noticed something that may explain why you have seen the startup fail with no additional information.
AddPythonApp()will try to run the app through OpenTelemetry auto-instrumentation wrapper (if it is present). We had a situation where the Python virtual environment was incorrectly configured and the path topython.exewas incorrect. In this case the OTEL wrapper would start, but then almost immediately fail with no output to standard error or standard output. Not a single byte; just exit with code 1. So that is what you would see in the Aspire dashboard, the app exiting with code 1, but no logs. Reflects the truth about what happened, but is not very helpful.How we figured it out was by looking at the application command line and parameters (which are visible in the Aspire dashboard) and trying the same thing manually from command line.
MedAnd commentedon Aug 6, 2025
Hi, any update on this issue? I am looking to run an Azure Function written in Python and cannot get it to start with "func start" and also does not have the correct virtual environment context.
For example it starts with the Global Python context, does not find my OpenTelemetry dependencies which are part of the activated virtual environment context etc.
davidfowl commentedon Oct 15, 2025
Few updates form this original issue:
There's be more in the future.