I write a code to import a particular module I create called “someModule()”, and if I do it like, from exampleScript import someModule, even without the brackets, this happens:
Python module can’t be imported - object ‘Cube’, controller ‘Python’:
Traceback (most recent call last):
File “exampleScript” line 4 in
ImportError: No module named ‘exampleScript.py’; ‘exampleScript’ is not a package
Seems weird… the BGE thinks its a “package”, when its clearly part of a script. A module is part of a script, not a package, which I believe is different.
This is an example scenario a typical person may run into.
You can even make your own modules in Python. Just use def example(): and some text to import the bge and logic and then use the example() to create the module! You can even do it with def main(): at the top of the script! (new module must be indented)
If the py file is on the same folder your blendfile is at, it should import.
It’d be useful if we could see the few lines of code that console is freaking out about.
Modules/Packages are similar in Python, but a module would be a Python file, named like some_name.py and that you import like import some_name. But it has to finish with a .py extension.
Then inside modules/packages you can have anything, such as functions, that you might import doing:
from some_name import some_function
some_function()