Tommaso Guerrini
Tommaso Guerrini

Reputation: 1718

FileNotFoundError: [Errno 2] No such file or directory in Pycharm

I'm pretty new with Python and finding some issues on a trivial code. I'm using Pycharm together with Anaconda.

This is my code:

posSentences = open('rt-polarity-pos.txt', 'r')

print (posSentences.read())

There is no issue in reading the file and printing it out when running it/terminal.

But when I try to run the same command in the console I get:

FileNotFoundError: [Errno 2] No such file or directory

I so checked the directories of the console, but they seem fine and are the same of the running file:

console setup

Thank you for your help!

Upvotes: 5

Views: 16721

Answers (1)

khajvah
khajvah

Reputation: 5090

Python interpreter is run from Desktop\textan but the file is in Desktop\textan\textan\ directory, so the path to the file in python code becomes textan\rt...txt

Upvotes: 1

Related Questions