Search code examples
pythonpyautogui

How do I fix the error FileNotFoundError: [Errno 2] No such file or directory?


I'm making a program to spam the bee movie script line by line.

import pyautogui
f = open('beemovie.txt', 'r')
for word in f:
    pyautogui.typewrite(word)
    pyautogui.press("enter")

and get the error:

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

I've checked if I spelt it right but it nothing seems to be working. I know this my have been asked millions of times but I can't find anything to help me. I've already made a text file with the whole bee movie script.

I'm using Pycharm if that helps.


Solution

  • It is possible that your file 'beemovie.txt' is located in a directory other that the working directory of your PyCharm debugger. One of the things you can try is to set the Working Directory (under PyCharm Configurations [Run->EditConfigurations]) to the directory where your file is.