Be the first to post for 'No Such Thing As Plain Text'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Really enjoying the course so far, but in this video I struggled with using

codecs.open(‘backers_10.csv’, ‘r’, ‘utf-8-sig’)

It was giving me error

File “D:\Program Files (x86)\Python\Python 3.5.1 (64-bit)\Lib\codecs.py”, line 895, in open
file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: ‘backers_10.csv’

Seems as though it was looking for the ‘backers_10.csv’ in my python folder instead of the folder containing ‘credits.blend’ and ‘backers_10.csv’. I got around the issue by entering a full path to ‘backers_10.csv’

3 Likes

I have both Mac, and PC and entering the direct path for the file will be a real pain. I’m totally not getting how to get it to find the file without the direct path myself

Hi guys, this is all about pathnames and path variables. Try double checking your code matches mine, and that you understand how the path is comprised and how to query it. Remember you can get to “Lecture code changes” from Resources.

I had the same error. Found a workaround here. Did an os.chdir(foldername) and everything works fine. Did os.listdir after opening credits.blend and it showed that the working directory was the one for Blender, not the directory with credits.blend.

Thanks for sharing

I had the same issue. Needed to put the absolute path in the get_backers method. Did so by repurposing the python functions utilized for the project startup snippets and a new variable that I passed in so that it would be OS-independent.

projectfilepath = os.path.dirname(bpy.data.filepath)
print(get_backers(projectfilepath + ‘/backers_10.csv’))

1 Like

Well done @kenmcdowell

It seems that (at least for Windows) the codecs don’t use the system path information for finding the file. When you open up Blender, the system current working directory is set to the blender directory, and that’s as far as the codecs module looks for files.
The solution is either
a) Specify the full path and file name in the open command or
b) use the os.chdir command to change the working directory to the directory that holds the file to be opened. I used b) and it looks like this
os.chdir(os.dirname(bpy.data.filepath))
assuming the file you’re trying to open is in the same directory as the blender project that you have open.
Another way is create a datafile name variable that will hold the path and the filename
datafilename = os.path.dirname(bpy.data.filepath)+'yourfilenamehere
codecs.open(datafilename, ‘r’, ‘utf-8-sig’)

1 Like

Posted on the Q& as i think this all boils down to python version 3.5.1 as the common denominator.
I rattled out a solution from the comments

1 Like

Thanks Marc

Hey there Im having the same problem. but when you say entering the full path to backerst do you do codecs.open(fullpath, ‘backers_10.csv’, ‘r’, ‘urf-8-sig’) ? or wherer do you put in the whole path? does it need to be in ‘’ ?
cheers :slight_smile:

I altered the When first opening Blender… import statement to include os.chdir(bpy.path.abspath("//")). So my import line now looks like this:

import os, sys; sys.path.append(os.path.dirname(bpy.data.filepath)); os.chdir(bpy.path.abspath("//")); import texture_painter

bpy.path.abspath("//") returns the absolute path of the current working directory of the blender file.

Privacy & Terms