I'm confused about how PyCharm determines the path Python uses to locate modules and packages.
First of all, when I uncheck the settings (in both the "Python Console" and my Run Configuration), I still see the directory for my project at the start of sys.path
.
For example, I have project in 'path problem' and 'Run" a file there containing
import sys
for p in sys.path:
print p
I get
/Users/Rax/Documents/Projects/pathproblem
... (other things in my PYTHONPATH)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages
even when I've asked for the "contents root" to be excluded from the path:
This can result in successful imports of modules that will fail to import in typical deployments (e.g. when building a package).
If I check the setting I get it twice:
/Users/Rax/Documents/Projects/pathproblem
... (other things in my PYTHONPATH)
/Users/Rax/Documents/Projects/pathproblem
...
It seems that PyCharm always adds the current project root at the start of (what it considers to be) the PYTHONPATH and that this setting just adds it again at the end.
(1) How do I configure PyCharm so that it (really) doesn't add the project directory to the package search path?
Also, as near as I can tell, PYTHONPATH, for PyCharm, is not my system PYTHONPATH at all, but the "user added" entries in — in fact, confusingly, at the end of — the Path settings for the Python Interpreter.
(2) Where does PyCharm's PYTHONPATH come from? It's not the PYTHONPATH I see anywhere else on my system.
FWIW, PyCharm's Sphinx respects "contents root" settings, adding the content root only when path when checked in the build configuration.