0

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.

Aleereza
  • 1
  • 2
  • Hello, I'm voting to close this question since it is not related to Blender, but an external IDE. See https://blender.stackexchange.com/help/on-topic – Gorgious Jun 15 '21 at 06:29
  • Hi @Gorgious.. I wonder where we should try to get help on using VSCode and its Blender extension. I keep running into (what I'm sure are are solvable) hitches myself. – Robin Betts Jun 15 '21 at 08:02
  • 2
    @RobinBetts Fair point, and I'm all for it, there is very little documentation about it :) . But the question didn't mention they are using the Blender VScode extension so I assumed it was a regular python environment since mathutils can 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:13
  • 1
    @Gorgious Ok, got you. A bit meta, this point..:) – Robin Betts Jun 15 '21 at 08:41
  • @Gorgious Hi, I appreciate the response. I added some detail about my setup at the bottom. please let me know if I should provide more info. – Aleereza Jun 15 '21 at 15:15
  • @AlirezaBarkhordari So the first print outputs are inside the VScode terminal ? How did you install the mathutils module ? – Gorgious Jun 15 '21 at 15:32
  • @Gorgious, yes the first one is in vscode. I didn't install mathutils specifically for vscode. when I run print(mathutils.__path__) in vscode it returns this: /home/alireza/.local/lib/python3.7/site-packages/mathutils – Aleereza Jun 15 '21 at 15:40
  • Not using vscode so cannot clarify, but is the mathutils or the bpy for that matter the actual blender python module, or a fake module for intellisence autocomplete etc? When running script from blender the bpy et al paths are prepended. What do you get for mathutils.__path__ in blender? – batFINGER Jun 15 '21 at 17:46
  • Hi @batFINGER, you are exactly right, the mathutils that vscode is using is the fake one I had installed for intellisence (by this command: /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 error AttributeError: module 'mathutils' has no attribute '__path__'. – Aleereza Jun 16 '21 at 16:23
  • Error is as expected so nevermind that message. (was making point they are not the same,) Look for "build bpy as a python module" There was also a recent post re mathutils being 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

0 Answers0