python controller module code works inside blender but not saved as game engine runitime I try to run a simple python invisible visible toggling python controller module. This works well inside blender, but not in the generated game engine runtime.

I have:


a 'Cube' mesh
a keyboard sensor named 'VisibilityKey' with 'All Keys' selected
a python controller in 'Module' mode with source 'mybpylib.visibilitytoggle'
controller and sensor are linked.


In the mybpylib.py file i have the following code:

def visibilitytoggle(o_ctrlr):
    if (o_ctrlr.sensors["VisibilityKey"].positive):
        for _ in o_ctrlr.sensors["VisibilityKey"].events:
            if (o_ctrlr.owner.visible == True):
                o_ctrlr.owner.visible = False
                print("i was visible")
            else:
                o_ctrlr.owner.visible = True
                print("i was invisible")


When I inside blender game engine press 'P' the invisible visibile  toggling of the cube woks perfectly by pressing any key.

When I 'File / Save As Game Engine Runtime' 
the game get saved, but when I start the executable the invisible visible toggling does not work.

I am using:


Blender version 2.78c (and corresponding blenderplayer) 
on MacOS X 10.12.5 (sierra)


I am still quit a blender noob.
It might be that I miss something simple but I can not figure out what.
Any help is appreciated.

Elmar
Monster's hint pointed me towards the real answer: Always look at the console window, when you are working with python. 
(HowTo is described here: https://wiki.blender.org/index.php/User:Fade/Doc:2.6/Manual/Interface/Window_system/Console_window .) When I was using the Embedded Player in the Blender Game Properties Editor, the console printed out that it not can "import bpy". 
So I realized that I only have to "import bge" and not have to "import bpy".

The second part to the answer I found in MikePan's answer in this post: 
Packaging external libraries in the game engine &#39;Create Runtime&#39;. I work on a Mac and I simply had to copy the python file withe code for the controller into the Content/MacOS/Resources folder of the Save As Game Engine Runtime generated app. 

This question and comments are as well related to the topic: BGE: where to place external python modules when exporting for Mac OS X