How to fix Python environment preparation failed error

How to fix Python environment preparation failed error

A very common error when executing automations through the Runner is Python Environment Preparation Failed.
As the name suggests, the Runner fails when trying to prepare the Python environment for the robot's execution.
This error occurs in different situations and prevents the Runner from running the robot.
Below are some scenarios and approaches on how to handle this error:

Scenario 1:

Environment Blocking – Runner Cannot Connect to PyPI (Python Package Index).

In some cases of environment restrictions, when running an automation via Runner, the following error may be thrown::

Warning
exec: C:\\Botcity\\.\\venvs\\SAP/Scripts/python -m pip install --upgrade pip Requirement already satisfied: pip in c:\\botcity\\venvs\\sap\\lib\\site-packages (23.2.1) WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/ ..... Python environment preparation failed. Error executing task: Python environment preparation failed....

Standard Response/Solution:

Based on the error message, it appears that the environment where the Runner is being used cannot establish a connection with PyPI (Python Package Index).
As a result, the Runner cannot execute the pip install command to install necessary packages.
This is common in corporate environments that have network restrictions, likely blocking communication with PyPI.

Please check with your infrastructure team if there is any blocking in place.
Here is documentation outlining the necessary network permissions for these cases:
https://documentation.botcity.dev/getting-started/prerequisites/#problems-with-blocking-environments

Scenario 2:

Error: Cannot invoke "java.lang.Process.waitFor()" because "this.process" is null while creating a virtual environment

Warning
Log Screen Process created Log Application Process created WAITING NEW TASKS... Executing task: Bot_LoginSAP... exec: python -m venv ./venvs/Bot_LoginSAP_I execAndWait - Error: Cannot invoke "java.lang.Process.waitFor()" because "this.process" is null

Standard Response/Solution:

Since the error occurred after trying to create the virtual environment, the issue is likely related to Python itself, such as:

  • Python is not properly installed.

  • Python is not included in the system path.

  • The virtualenv package is not installed.

To verify Python installation, you can run the commands:

  • python --version
  • where python

If you receive a valid Python version output from these commands, ensure the following packages are installed:

  • pip
  • virtualenv

The easiest way to ensure everything is set up is by running:

  1. python -m pip install --upgrade pip setuptools virtualenv

Scenario 3:

Python Not Found in the Execution Environment

In some cases, Python cannot be found when running automation through the Runner.

Standard Response/Solution:

To confirm that Python is installed on the environment, you can use:

  • python --version
  • where python

In some environments, there may be two versions of Python installed. It is common for them to be accessed through different commands. You can check by running:

  • py
  • python

If the desired version is being accessed through the py command, and you want the Runner to use it for environment preparation, you must add the following line to the Runner's configuration file (conf.bcf located inside the conf folder of the BotCity SDK):

Alternatively, you can specify the full path to the desired Python executable by setting the pythonBinary flag like this:

  1. pythonBinary=<caminho para o python.exe>

Quote
Always use double backslashes (\\) in the path to prevent single backslashes from being interpreted as escape characters during execution


    • Related Articles

    • SSL Certificate Error When Connecting to Maestro in Python

      Why did the bot fail to connect to Maestro? The bot failed because, in Python, the call to Maestro did not ignore the self-signed SSL certificate from the proxy or server. This issue is common in corporate environments that use internal certificates ...
    • Error Running Edge Browser via Orchestrator: How to Fix It?

      Issue During the execution of robots using the Microsoft Edge browser through the orchestrator, a specific issue was identified: the browser did not start correctly, whereas when running locally, the flow executed normally. The error presented was: ...
    • Error Running Wizard.exe: How to Fix It?

      Issue When attempting to start the installation, configuration, or authentication process of the BotCity Runner using the wizard in .exe format, you may encounter difficulties opening the file. This error usually occurs due to company security ...
    • Why is the Runner stuck on "Executing task..." and how to fix it?

      Overview Occasionally, the BotCity Runner may appear stuck after retrieving a new task from the queue. In these cases, the status remains as: Executing task... and the automation does not actually start until the Runner is manually restarted. Likely ...
    • How to Diagnose and Fix Installation, Authentication, or Execution Issues with BotCity Tools

      Diagnosis To assist in identifying these issues, starting from version 1.2.5, the Wizard now includes the Diagnostic tool, which aims to check: Connectivity with BotCity services Possible network blocks Installed versions of Python and Java in the ...