File Can Be Found In Console But Can't Be Found Using Run Tool Window
I'm using Pycharm on OS X. The structure is: /Project /src codeA.py codeB.py /Data data.txt src is marked as Sources Root and Data is marked as Resource root. The problem
Solution 1:
Pycharm's console will include project root to PYTHONPATH
. You can see and set this in Settings > Build, Execution, Deployment > Console > Python Console
.
Your run config is probably wrong, ensure the working directory is correct, and that Add content/source roots to PYTHONPATH
checkboxes are checked.
To avoid any path problem, it is advised to work with absolute path:
# get project path from main entry file
file_path = os.path.dirname(os.path.abspath(__file__))
project_path = os.path.abspath(os.path.join(file_path, os.path.pardir))
data_path = os.path.join(project_path, 'Data/data.txt')
Post a Comment for "File Can Be Found In Console But Can't Be Found Using Run Tool Window"