Advanced Godot | Integrating Python into Godot

Hey guys, today we are going to talk about how to integrate Python into Godot.

Why?

Because Python allows you to have a lot of nice features and plugins that Godot does not offer at this time! Also its really cool to learn how it all works!

Downloading the Prerequisites

The first thing we need to do is set up our system. So lets go out to www.python.org to download Python.

Go ahead and click Python under the downloads menu. Now go ahead and install python onto your system. This language is very useful not just for this tutorial but any C++ development you may do in the future.

Once you have it installed go ahead and open up a command prompt and type python

It should print your version of python you downloaded! Awsome now that we have that lets go ahead and get pip go ahead and type exit() to shutdown your python instance and type:

pip install scons

In my case I already have it installed.

Next go out to here and download Visual Studio and install it. When it comes up asking you to select your work loads be sure to select desktop development with C++ you need this to compile Godot.

Downloading Python Godot and Setting it Up

Lets go out to here and lets pull down the code. If we click on the green code button you can see we can get out git repo.

Go ahead and hit the little clipboard to copy the url.

Now that we have that lets go back to our command line tool and type

git clone https://github.com/touilleMan/godot-python.git

This will clone our repo into the folder we are in. In my case its going to be going to my documents folder. After its done cloning go ahead and cd into your godot-python folder and type

python -m venv venv

This will create our virtual environment. Virtual environments are useful because they allow you to install packages without affecting your master python environment. From here lets type

ven\Scripts\activate.bat

Next we need to type

pip install -r requirements.txt

If you run into any of these errors first try and run your command with –user

If that does not work go out to your python venv and open up your pyenv.cfg file and set your include-system-site-packages = true and go ahead and run it again.

Compiling our Python Godot

Now that its done lets compile our Python version of Godot! Go ahead and type

scons platform=windows-64 release

This will download and install our python prerequisite files.

Now that we have our stuff built out lets go ahead and test it. Lets type

scons platform=windows test

Getting into Godot

Now that our tests have passed lets go into our build/windows-64/platforms and you will see we have Godot_v3.2.2-stable. The version will be dependent on what the version is at the time.

Lets open it, create a test project, add a node to the scene, and try to add a python file to our project.

Well that didn’t work… So for this to work we need to install a plugin as well into Godot so lets go download that. Open up the asset library and type Python.

We want to download and install PythonScript. We do not want to download PythonScript-pypy. THIS IS THE OLD VERISON OF THE PLUGIN AND DOES NOT WORK.

Go ahead and install it.

Now that its installed lets check if we have Python in our Attach Node Script dropdown. Nope… The reason this is is because we need to reboot Godot for it to recognize the new script type.

After a quick reboot we are back in business!

From here we are going to make a small sample py file and we are greeted with our usual file but its written in Python!

Now in the ready lets type

print("test")

If we run the project we notice it runs! We see test in our debugging console!

Exporting

If we want to export we can go out to our export menu. Lets click on the add button and add a windows export. Youll notice an error immediatly

Go ahead and click on manage export templates on the bottom.

This will popup the export templates menu. You will see we are missing some export templates here so click download and select your mirror.

Now that that’s done lets go out to our export menu again and move over to our resources. we need to make sure we get all the data included in our export. So head over to resources and add addons/*. This will add in our python export data with our project.

Now lets click on export pck/zip. Name our export and export it out as a zip file. In my case I’m goign to call it test.zip

From here we can extract our files and take a look at them. It looks like we are missing some of the files we need. Lets reexport:

That’s better, now we need to get our windows exe.

Lets go out to our export templates folder in my case its username/AppData/Roaming/Godot/Templates/3.2.2.stable and grab out windows 64 debug export template and copy it over to our folder.

Sweet it executed! That’s what we wanted!

Conclusion and Some Limitations

There are a few limitations here, first intellasense doesn’t seem to work at the time of writing, Exporting is kind of a pain, and I’m told mobile support is lacking but it does work!

But that’s all I have for you guys today so thank you so much again for reading and ill see you all next time!

Companion Video

Default image
Mitch
Articles: 15

Leave a Reply