# FileNotFoundError: [Errno 2] No such file or directory - Blender Python API

Hello Blender Community,

With my groupmate, we are working on a traffic simulation on Blender as our graduation project. Initially, the simulation engine runs and outputs a .txt file, sim_log.txt, containing the details to be processed by the script on Blender. Then, we run the script and get a visualization of the traffic flow.

Sometimes, I could not really figure out why, the Blender script throws the following exception when trying to read the output file which is in the same directory with the .blender file:

Info: Deleted 0 object(s)
Traceback (most recent call last):
File "C:\BlenderTest\CS402\SimulationAnimator.blend\Text", line 24, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'sim_log.txt'
Error: Python script failed, check the message in the system console


The script up to the line that the error occurs is as follows:

import bpy
import os
import numpy
import random

#Test values
time = "day"

# Clean console, view and orphan data
os.system("cls")
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.types.BlendData.orphans_purge()

# Set world background
if time == "day":
else:

cameraCar = "" # Name of the car that camera will follow


I think based on the Error that open is trying to load the file from the Blender project as a directory, but the project is a file and doesn't have this subdirectory "Text". You could probably fix this by using an absolute path and store the "sim_log.txt" in the same directory of the blender project. To get the absolute path you could use os.path.join(os.path.dirname(bpy.data.filepath), "sim_log.txt")