JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
557 stars 76 forks source link

Fix for issue #23 ModuleNotFoundError #42

Closed schlegel11 closed 5 years ago

schlegel11 commented 5 years ago

Hello, this commit should fix the ModuleNotFoundError issue -> #23.

Behaviour: If an addon is initial created in the blender config path".../.config/blender/2.80/scripts/addons" and the blender start command is executed from visual studio code, blender can't load and enable the addon due to a ModuleNotFoundError exception. If the blender start command is executed a second time, the addon can be loaded an no ModuleNotFoundError exception occurs.

Cause: The module can't be loaded the first time because the ".../.config/blender/2.80/scripts/addons" path is not in the python module path so the list sys.path doesn't contain the addons path. I don't know why blender can't recognize the correct path the first time. One interesting thing to mention is, that the path ".../.config/blender/2.80/scripts/addons/modules" is included in sys.path. So the sub dir "modules" is included but not the parent "addons".

Solution: To make sure the ".../.config/blender/2.80/scripts/addons" path is included in sys.path and the module can be loaded by blender, I add a condition in the setup_addon_links method. If the path doesn't exist, it is added to sys.path.

JacquesLucke commented 5 years ago

Thank you :)