How to keep python script in the game once made into a blender program standalone file?

Hi, how do I keep the python script with a mini game that is an executable? In blender it works fine, but once a program file that scripts aren’t kept, so the game isn’t complete without the code. pycache folder is the solution to this? I had one script in it, but that didn’t give a load screen, it could be that one was missing from the folder. But I am sure it should of worked as is.

If you’ve imported the scripts into Blender before exporting the blend as an executable with the runtime addon, than Blender should automatically include it into the executable.

If you have not imported it into Blender and have been dynamically importing the scripts at runtime than you’ll need to setup a relative path system and place the Python scripts (.py, .pyc, etc) into the exported executable’s folder.

Hmm, all I have ever done is export as the executable, but no blend file with it. So the only change I saw on the other computer I have access to which can run the game engine fine, that there was a py folder.

I decided to try and create a new exe, with both or one of the options for the addon game engine list that is available.

I got these errors, textures and sounds or not unpacked, and the other default.

No idea what this means.

And that also means as blend.exe or just an exe, and or using 2.76 or 2.78

Very odd, never seen this type of error, not that I can ever remember. My last file exe was made in late 2019.

The good news, this is no longer a problem, I used 2.78, unpacked file in a folder and exported as exe. So the question now is python scripts. So this is the current new exe folder setup. Sounds folder, textures. pycach should be there with a script or how ever many? I find it funny I found this out so late…

Color management: using fallback mode for management

BGE & UPBGE 0.2 only supports the color management types; sRGB, or None (Linear).

UPBGE 0.3 supports all types I think.

BLT_lang_init: ‘local’ data path for translations not found, continuing

Symlinks bug, fixed here: https://developer.blender.org/T42729

The instruction at 0x00007FF6C4E059A8 referenced memory at 0x0000000000000000. The memory could not be read.

Click on OK to terminate the program

Your computer ran out of RAM due to Blender’s memory not being freed after rendering.
Bug fixed here: https://developer.blender.org/T54287



Please note that upgrading to any UPBGE release/version resolves a lot of these errors!



For compiling .py scripts to .pyc you simple use Python arguments:

python –m compileall –b

I think you can also simply run a script in a saved blend and Blender will automatically generate the .pyc and place it in the current blend directory. Not sure*

I don’t know about upbge.

I have one file that works in upbge, and anybody who has time can get the spider smith working against the player, and so on. stab fight effect to attack the AI.

As for the python, for example, when one user helped me with the robot file, there is a script, its there open in a window, it was saved as something in the save as or what ever now, so the scripts are separate from the blend file, but they are in the file, otherwise they wouldn’t be there once loaded.

So yes I didn’t realise when I compiled the exe files two years back, the scripts weren’t with them. :roll_eyes:

When I have compiled as I did yesterday successfully, there was no python script added in the folder I compiled to, only textures and sounds.

https://blenderartists.org/uploads/default/original/4X/9/2/c/92cc60bf581ee531b48955e3f90da6b545c7968c.jpeg

Same as the last post image. So there you go, I don’t know why there is no python script.

So nothing. I tried the brick ai blend file since this would be fine as a basic example, where is the script? Not there.

The generated .pyc file should be in the directory that your blend file is in; unless you stated another file-path.

The blend file and the py are on the desktop.

So once exported as an exe, into a new folder, so as seen in the image, where would the .py file be, it isn’t in the 2.76 with a load of python files there. I even did a search for newprogram.py

Blender automatically embeds scripts into itself, there is no need for packing of it.
As for where the .py file is. Can you describe the method of how you exported it. e.g from the Text-Editor or created it in Notepad and exported it.

Python scripts are searched for in sys.path. Either put the scripts next to the executable, or add the path that they’re located in to the sys.path.

import sys
import os

sys.path.append(os.getcwd() + '\\my_directory_of_scripts') # this folder would be in the same folder as your executable

The “current working directory” is in sys.path, which is why having the scripts in the same folder as the blend/executable works.

1 Like

Well, I just saved the script in a place, and its with the blend file, no different than images or sound packed, so why the script isn’t with the exported files, I don’t know.

The export just takes the blend and mashes it together with the blenderplayer. It’s up to you to copy the rest of the dependencies.

Well I tried putting one of the python scripts in the folder along with all the dll files, but there wasn’t any change.

The second file I have has the scripts, so it works it should.

I don’t remember if the robot file had a end scene once the robot was shot. That was why I questioned if the python script was suppose to be loaded in. I don’t remember from this, since this was compiled in november 2018.

It doesn’t matter. What is important is the file before is working now.

if you want to have the python scripts included in your exported game exe, make them part of the blendfile that needs it, you do this by making it internal in the blend.

if you see a file path here then you script is external.

to make it part of the blend do this.

and now it should say internal.

I managed to solve this for my file. I placed them or what ever now, it works as an exe with a script to trigger the event needed, as before the game was just continuing.