Running Blender via Python 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.
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"