-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to develop an Android .NET MAUI app using CSnake? #322
Comments
I'm working on a solution to this at the moment. I'll add another automated locator which pulls in managed versions via UV/Astral's service. https://docs.astral.sh/uv/concepts/python-versions/#managed-python-distributions At the moment, the only solution for this is to use the nuget package, but that only bundles Windows x86_64 binaries. |
That solution is released in the newest version, see release notes and please let me know if this works for your use case. Use .FromRedistributable() on the environment builder and it will download Python for you. |
I have added the .FromRedistributable() locator to the environment builder and no error is reported, but when the program reaches the line "var env = app.Services.GetRequiredService();" it stops after about 6 minutes throwing the exception "System.TimeoutException: 'Python installation timed out.'". I'm reporting exactly what it happens as I'm not an expert and I can't judge if it is a problem related to my program or to the .FromRedistributable() Locator. I can say that the same program for Windows machine using python from the FromNuGet or the FromFolder locators works. using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using CSnakes.Runtime;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using System.Diagnostics;
namespace PythonApp
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
var home = Path.Join(Environment.CurrentDirectory, "..", "..", "..", "..", "PythonDependencyProg");
var venv = Path.Join(home, ".venv");
builder.Services.WithPython()
.WithHome(home)
.WithVirtualEnvironment(venv)
.FromRedistributable()
.WithPipInstaller();
builder.Services.AddSingleton<MainPage>();
var app = builder.Build();
var env = app.Services.GetRequiredService<IPythonEnvironment>();
RunDemo(env);
return app;
}
public static void RunDemo(IPythonEnvironment env)
{
var demo=env.Demo();
string output = demo.HelloWorld("cami");
}
}
} |
I'm experimenting with MAUI desktop apps in #341 and will look at mobile after that. |
This sounds like a timeout waiting for the mutex and another installation to complete. Is it possible that you had an instance of the app running blocked and you launched another instance that then timed out waiting for the first one to complete? My gut feeling says that the first instance remained blocked waiting for the download to complete on the UI thread, but which is busy serving the download in the first place; therefore deadlock! I just opened PR #345 that should hopefully address this. |
It seems that the main issue is that CSnake needs python to be installed on the device to work. Is it possible to bypass this point? Do you have any suggestion on how to face it?
The text was updated successfully, but these errors were encountered: