OSError when starting Blender from the command line with '--python' option
Closed this issue · 2 comments
Blender Version: Blender 2.79
D-NOISE Version: 1.1.0 (DNOISE_v1_1_b2_79.zip)
Description
Hi Grant,
I had this issue reported to me by a user trying to run a FLIP Fluids simulation from the command line. Baking from the command line involves running Blender in the background with the '--background' option and loading a python script with the '--python' option. It looks like there is a conflict with D-NOISE that is causing Blender to produce an OSError which prevents the script from running.
How to Reproduce
I have constructed a minimal method of reproducing this error. Here is an example command run from the Windows PowerShell command line:
& 'C:\Program Files\Blender Foundation\Blender\blender.exe' --background --python python_script.py
I have attached the python script here: python_script.zip which just contains print statements:
print("Running python script...")
print("Python script finished.")
When launching Blender with the above command I get the following error:
OSError: Python file "C:\Users\ryanl\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\DNOISE\python_script.py" could not be opened: No such file or directory
Blender quit
The OSError causes Blender to terminate before running the script.
Possible Fix
I checked out the D-NOISE scripts and it looks like there are a few areas where os.chdir()
is being used to change the python working directory. It seems this is causing a problem with the filepath when Blender tries to load the python_script.py
file.
Specifically, the clean(directory, fileformat) method in fmutils.py seems to be causing the issue:
def clean(directory, fileformat):
"""Deletes all files of a given format from a directory"""
os.chdir(directory)
for file in os.listdir(directory):
if fileformat in file:
os.remove(file)
A possible fix is to save the current working directory into a variable and then reset the directory after the method is finished:
def clean(directory, fileformat):
"""Deletes all files of a given format from a directory"""
original_directory = os.getcwd()
os.chdir(directory)
for file in os.listdir(directory):
if fileformat in file:
os.remove(file)
os.chdir(original_directory)
After making this change, the script runs without errors:
Running python script...
Python script finished.
Blender quit
Workaround
This isn't a huge issue. A quick workaround is to disable the D-NOISE addon.
I will fix this ASAP along with a lot of other changes that need to happen. Thank you for the heads up and for the detailed issue description!