How to Fix Visual Studio Code’s Run Python in File Directory for Opening Files

Bryan Siegel
April 1, 2020

So I was going through Lynda’s Python Essentials training and ran into a snag. While manipulating files I noticed I kept getting an error

FileNotFoundError: [Errno 2] No such file or directory: 'lines.txt'

I was like no way. I know that the lines.txt file is in the same directory. Here is the structure I was working with.

As you can see lines.txt is in the same directory. So my code should of worked. Well I did what any developer would do and I used a different editor PyCharm. Guess what it worked. While PyCharm is cool and all I can’t stand the way the color themes are setup. I’ve downloaded a crap ton of themes and they are all garbage. But anyway back to solving the issue.

So I dug around in settings until I found this gemExecute in File Dir

If you’re using the Python extension from Microsoft like me all you have to do is select “Python > Terminal: Execute in File Dir” from the extensions settings and tada issue fixed.

Tags

Python

Would you like to hire me?

Side projects, Employment Opportunities, you want to give me a [big bag] of money.

Contact