I am using VSCode as external IDE for writing Blender scripts/add-on. I am getting incorrect results when I run python script in vscode for the following code:
import mathutils
my_vector = mathutils.Vector((1.0,1.0,1.0))
print("type: ", type(my_vector))
print("length: ", my_vector.length)
print("x: ", my_vector.x)
results:
type: <class 'mathutils.Vector'>
length: None
x: None
The exact same script in blender text editor gives the correct result:
type: <class 'Vector'>
length: 1.7320508075688772
x: 1.0
Both are using the same Python executable and sys.path.
my setup:
OS: Ubuntu 20.04.2 LTS
Python executable: /usr/lib/blender/2.91/python/bin/python3.7m
Installed Python, and Blender Development extensions on VSCode.
Installed debugpy and flask on python.
mathutilscan also be used in a standalone environment. That would explain why they behave differently. Maybe OP could add a little more information on how they setup the IDE and python environment. Either way, I feel like it's really hard to answer the question in this state – Gorgious Jun 15 '21 at 08:13print(mathutils.__path__)in vscode it returns this:/home/alireza/.local/lib/python3.7/site-packages/mathutils– Aleereza Jun 15 '21 at 15:40mathutilsor thebpyfor that matter the actual blender python module, or a fake module for intellisence autocomplete etc? When running script from blender thebpyet al paths are prepended. What do you get formathutils.__path__in blender? – batFINGER Jun 15 '21 at 17:46/usr/lib/blender/2.91/python/bin/python3.7m -m pip install fake-bpy-module-2.91 --user). Thanks for pointing out the problem. But now I dont know how to make it use the correct one because in the Blender python console,mathutils.__path__returns an errorAttributeError: module 'mathutils' has no attribute '__path__'. – Aleereza Jun 16 '21 at 16:23bpyas a python module" There was also a recent post remathutilsbeing available as a stand alone module. https://blender.stackexchange.com/questions/186553/use-blender-python-libraries-outside-blender/186554#186554 – batFINGER Jun 16 '21 at 16:36