Sunday 22 November 2020

PyCharm adds current file and parent directory to path

I'm using PyCharm on Windows 10 with Python 3.8. I was trying to get Python imports working from a parent directory using:

import sys
sys.path.append("..")  # Adds higher directory to python modules path.
from trace_recursion import trace

It worked fine, but then I noticed that commenting out sys.path.append("..") # Adds higher directory to python modules path. also worked.

I checked this out running from a terminal, and commenting out sys.path.append("..") broke the program, as expected.

I then did a text comparison of the output of print(sys.path) and the output from PyCharm includes the current file and the project directory, whereas the output when run from a terminal does not.

What is going on here please? Has PyCharm cached the extended path from the first time I ran sys.path.append(".."), or is it some kind of default behavior of PyCharm to add that anyway? Or something else?



from PyCharm adds current file and parent directory to path

No comments:

Post a Comment