'Why is a pyautogui script not executed in the background using dart's Process.run()?

Edit: Problem Fixed. Just needed to replace "python3" with "python3.9" in my flutter code.


I have a pyautogui script. I have made a flutter app in which I have a button. When the button is pressed, the python script is executed in the background. What I can't understand at all is that the pyautogui part does not work. It works when I manually type "python3 <script.py>" in the terminal but not in Flutter.


And I am 100% sure that my python script is executed because I ran a "print" command in one script and tested the output using result.stdout in dart and Flutter was showing the correct output.


Any ideas?


Dart Code:

import 'package:flutter/material.dart';
import 'dart:io';

void main() => runApp(
      MaterialApp(
        home: tuxHomePage(),
      ),
    );

startPython() {
  Process.runSync("python3", ["myScript.py"],
      runInShell: true, workingDirectory: "/home/kq1231");
}

class tuxHomePage extends StatelessWidget {
  const tuxHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(children: [
          Container(
            width: 100.0,
            height: 50.0,
            child: ElevatedButton(
              onPressed: () {
                startPython();
              },
              child: Text(
                "Go !",
                style: TextStyle(fontSize: 30.0, color: Colors.white70),
              ),
            ),
          ),
        ], mainAxisAlignment: MainAxisAlignment.spaceEvenly),
      ),
    );
  }
}

Pyautogui code:

import pyautogui
pyautogui.click(x=500, y=660)

I'm expecting the script to click at (500,660) but it doesn't click. And other pyautogui functions don't seem to work as well. If I execute the script in my linux terminal, it works.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source