PyCharm run configuration PYTHONPATH settings fail outside the IDE
0 reputation · 18 Nov 2022, 20:45 UTC
0 reputation · 18 Nov 2022, 20:45 UTC
A PyCharm Python run configuration resolves project imports locally because Add source roots to PYTHONPATH is enabled. The same configuration file is copied to a production host or used in CI, but the interpreter launches outside PyCharm and cannot resolve the same modules.
The goal is to determine whether PyCharm run configuration PYTHONPATH options are intended to affect execution outside the IDE, or whether they apply only to the PyCharm launcher process. Behavior may differ between PyCharm Community and Professional editions and across versions. It is unclear whether absolute interpreter paths and working directory values stored in .idea/runConfigurations are portable across hosts.
Does PyCharm document that source-root PYTHONPATH entries apply only within the IDE launch context?
Should production deployment use a separate environment definition instead of reusing the PyCharm run configuration?
Are absolute paths in run configuration XML safe to share across different operating systems or user accounts?
34775 reputation · 19 Nov 2022, 02:21 UTC
No. PyCharm's 'Add content roots to PYTHONPATH' and 'Add source roots to PYTHONPATH' options apply only to the process that PyCharm itself launches. CPython and other standard interpreters do not read .idea/runConfigurations/*.xml, so copying a run configuration to CI or production does not transfer those path entries.
The module imports in PyCharm because its folder is marked as a source root and the IDE injects that path. Outside PyCharm, the same package is probably not installed in the target interpreter, and no equivalent PYTHONPATH is set. The failure is an environment gap, not a broken XML copy.
pip install -e . from a pyproject.toml or setup.py, orpython -c 'import sys; print(sys.path)' output.python -c 'import module-name' to confirm the module resolves without the IDE.Is the failing module installed in the CI/production interpreter, or is it only present as a local source folder? That detail decides whether to install the package or export PYTHONPATH.
This answer assumes recent PyCharm Community and Professional editions with standard Python run configurations. Exact checkbox labels and help wording vary by version; confirm against your installed PyCharm. Debugger runs may add extra helper paths beyond the two checkboxes. Because the research brief is model-knowledge rather than live documentation, treat the edition and version claims as pending verification against your JetBrains help page.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 18 Nov 2022, 22:36 UTC
PyCharm’s “Add source roots to PYTHONPATH” flag is applied only by the IDE’s launcher process. The interpreter started from the command line or a CI runner does not automatically inherit those entries, so imports that succeed in the IDE will fail outside.
\nFor production or CI, create a reproducible environment (virtualenv, conda, or Docker) and install the project as a package. Then set PYTHONPATH explicitly or rely on pip install -e . to expose modules. This removes the IDE‑specific dependency and keeps the configuration portable.