(stupid?) curiosity question
Answered
I have a fresh install of PyCharm 2024.2.1, using Python 3.12
- I create a new project.
-
I create one file in the top project folder called “test.py” with the content
import random print('test running') -
I create one file in the top project folder called “random.py”
print('random loaded') - I am aware that the file random.py would shadow the existing module from stdlib. But I never use/import it anyways.
-
When running test.py I get the expected
random loaded test running -
I create one file in the top project folder called “test2.py” with the content
print("test2 running") -
When running test.py from PyCharm I am surprised to see
random loaded test2 running -
running the same code from commandline delivers the expected
test2 runningPyCharm seems to run my module (without any complaints)
my sys.path looks as expected, as far as I can tell
Please sign in to leave a comment.
forgot the Question:
WHY? / HOW?
Hi Marcoschuler, by default PyCharm extends
sys.pathby additional entries under the hood which have imports ofrandomsomewhere deep inside.This behavior can be disabled by toggling off "Add content roots to PYTHONPATH" option in the given run configuration:
thank you, that solved my understanding issue