EDIT: Hopefully clearer answer in response to comments.
The short answer is 'No, you can't do that'.
The long answer
The reason this works in VSC is that Python has a system variable called PYTHONPATH
. Python searches all of the directories in PYTHONPATH
to find the file. VSC knows this and adds the directory containing your module to PYTHONPATH
.
For various reasons, Blender ignores PYTHONPATH
by default. So it can't find modules that VSC can.
The workaround
You can work around this by
- running Blender with the command line argument
--python-use-system-env
and
- Adding the parent directory of your module to the search path using code along the lines of
import sys
sys.path.append("PATH_TO_YOUR_MODULE")
before you try to import it. That's only the path to the directory containing the module. Don't include the module name.
Background
You may want to read the Python manual section on the import system; especially the paragraph about searching. The key bit has to do with import path
A list of locations (or path entries) that are searched by the path based finder for modules to import. During import, this list of locations usually comes from sys.path, but for subpackages it may also come from the parent package’s path attribute.
For a discussion of Blender and PYTHONPATH
, see this answer
from .subp.panel import Panel
and see if that works. $\endgroup$ModuleNotFoundError: No module named 'subp'
. $\endgroup$__init__.py
file in the root of your custom module? $\endgroup$Overlay - __init__.py, panel.py
right now. $\endgroup$