Importing modules and packages without appending new text data-blocks

Hey folks,

I’m just lost on how to get Blender to find my scripts without appending them to the .blend file itself or dumping everything inside the same folder. I know I can specify the path to my libraries or move my code to the Blender directory, but that’s not useful as I want to distribute a standalone executable.

What I’d like to do is keep my code orderly and structured within the folders of an individual, multi-file project, so that I can import classes and functions when I need them and not clutter my text editor with buttloads of files anytime I just want to create a new actor and have him walk around a bit. Is this possible or just too much to ask?

Replying to myself just in case I wasn’t clear enough.

I know I can just…

#top level
import os,sys
sys.path.append(os.getcwd) #or relative path
import package
#or rather
from package import module

And that would work just fine for me, the question here is, how do I construct the path so that the standalone player doesn’t go stupid when someone else opens the executable?

path = bge.logic.expandPath('//map_name/script.py')
where // stands for the root directory (where the blend is running from)

same for the brick //map/script.function_inside_script

So I can use expandPath to find any type of file within my subfolders, correct? That’ll come in handy. Thanks!

No need to fiddle with paths within your code. You can use the method described in this thread:

Easy access to your python folders

Superb! Exactly what I needed. Why didn’t that thread show up in my search though? Guess I’ll have to check my wording next time.

Good to hear.

I think the search should be much better than before.