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 &quot;C:\BlenderTest\CS402\SimulationAnimator.blend\Text&quot;, line 24, in &lt;module&gt;
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 = &quot;day&quot;

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

# Set world background
if time == &quot;day&quot;:
    bpy.data.worlds['World'].node_tree.nodes['Environment Texture'].image = bpy.data.images.load(&quot;//hdris\day.hdr&quot;, check_existing=True)
else:
    bpy.data.worlds['World'].node_tree.nodes['Environment Texture'].image = bpy.data.images.load(&quot;//hdris\\night.hdr&quot;, check_existing=True)

cameraCar = &quot;&quot; # Name of the car that camera will follow

# File read section
f = open(&quot;sim_log.txt&quot;, &quot;r&quot;)

I mostly encounter this problem after another program accesses this file, but sometimes it occurs randomly. I could not find a way to tell Python API/Blender that the file actually is there, so I have been copying the file and updating the filename in the script. I thought the community could spot the problem, so I would not need to work with sim_logv19.txt anymore :)
If you would like to take a look at the project repository, here is the link:
https://github.com/sefasenlik/TrafficSim
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 &quot;Text&quot;. You could probably fix this by using an absolute path and store the &quot;sim_log.txt&quot; 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), &quot;sim_log.txt&quot;)