0
$\begingroup$

I'm learning blender and want to create my own module with a custom UI. I'm stuck at the gate just trying to import Blender to run through independent python scripts:

import subprocess

bPath = "C:\Program Files\Blender Foundation\Blender\blender.exe"

subprocess.run([bPath, "--background", "--python", "myScript.py"])

All that's in myScript.py for testing is:

import bpy

bpy.ops.mesh.primitive_cube_add()

All I want to do first is load up a blender render window from Python that makes the cube, ideally one stripped of the interface. I can figure the rest out from there.

My error is

FileNotFoundError: [WinError 2] The system cannot find the file specified

Any help would be much appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$
FileNotFoundError: [WinError 2] The system cannot find the file specified

This suggests there is a problem with the path to something in your script. I think you may need to give the absolute filepath to your myScript.py file.

Also, the "\" is an escape character in python, so if you're going to use it in the filepath to something, then you should use one of these methods:

bPath = r"C:\Program Files\Blender Foundation\Blender\blender.exe"

or

bPath = "C:\\Program Files\\Blender Foundation\\Blender\\blender.exe"
$\endgroup$
3
  • $\begingroup$ Thanks, that was my noob mistake. Is there a way to get blender to create a viewport this way? $\endgroup$ Mar 20, 2018 at 0:57
  • $\begingroup$ Opening blender with the "--background" flag means you're opening blender without a UI. From what you've said, it sounds like what you want to do is make an Addon. I recommend downloading someone else's well-made addon and having a look at their code and reading this tutorial. $\endgroup$
    – doakey3
    Mar 20, 2018 at 1:37
  • $\begingroup$ Thanks, I was able to get a blender window to show up with the cube added. I will sort the rest out from here. $\endgroup$ Mar 20, 2018 at 1:58

You must log in to answer this question.

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