0
$\begingroup$

The problem:

I've created two scripts in blender (importTest and loggingConfig), as shown in the following picture:

Modules example

But when I try to import loggingConfig I obtain the error

ModuleNotFoundError: No module named 'loggingConfig'

Options tried:

importTest (Try #1):

import loggingConfig

importTest (Try #2):

import bpy
import sys

dir = bpy.data.filepath
print(dir)
if not dir in sys.path:
    sys.path.append(dir)

import loggingConfig

In both cases obtaining the error above

$\endgroup$

1 Answer 1

2
$\begingroup$

For blender below 2.8

The script to be imported must have the '.py' suffix (e.g. loggingConfig.py), it can be imported as follows:

import loggingConfig

If loggingConfig suffered any changes, you must reloaded, like this:

import loggingConfig

# The following lines reload the module in each run
import imp
imp.reload(loggingConfig)

This can be ran each time to ensure to have always the most up to date version of loggingConfig.py.

For blender >= 2.8

The script to be imported does not need to have the '.py' suffix (e.g. loggingConfig), it can be imported the following:

import bpy

loggingConfig = bpy.data.texts["loggingConfig"].as_module()

In this case it isn't necessary to reload the script in each run.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .