Getting started with the Python Bridge

The default way to get started with the Python Bridge works on all supported GT platforms and uses a specific approach to handle control of the Python runtime environment. From the GT side everything needed is included in the standard image and standard distribution.

External requirements

Obviously you need to install Python itself. If your operating system already has a recent Python version installed then you are good to go. Using a standard operating specific way to install Python is probably the preferred way. In any case, there are many websites describing how to do this, like the main website.

You should be able able to open a terminal or command shell and do the following (the binary can be named python, python3 or python.exe).

$ python3 --version Python 3.11.7

Next you need to install a tool called pipenv. Please follow the instructions at the tool's main website. In the end, the following should work.

$ pipenv --version pipenv, version 2023.11.15

Now you are all set.

There is also a Python Bridge troubleshooting page in case you need more help.

The global instance

The default approach is to use a global instance of the Python Bridge which is very convenient and makes it easy to use from several places.

PBApplication uniqueInstance
  

Initially this singleton is nil. It gets created the first time you try to start the Python Bridge. When creating a new instance, configuration settings are used. These settings define many aspects of the bridge infrastructure. For now, we'll leave them alone.

Now try starting the Python Bridge. Please be patient, this takes a while (10s of seconds) the first time as some installation needs to happen.

PBApplication start
  

If all is well, you should see useful information in different tabs when inspecting the PBApplication LanguageLinkApplication subclass: #PBApplication instanceVariableNames: '' classVariableNames: 'DebugMode' package: 'PythonBridge-Global' instance. In particular, the Details view should show a green true value for the client and server processes and not a red false value.

When using Python Snippets you will implicitly use this same global instance, transparently. It will start automatically.