Why does PyCharm maps relative directories from PYTHONPATH in Docker container?
When using run configuration based on remote Python interpreter based on Docker compose and setting PYTHONPATH
environment variable in the run configuration like this:
PYTHONPATH=dirA:dirB:dirC
(where all dirA
, dirB
and dirC
are relative paths)
PyCharm sets PYTHONPATH
in the container like this
/opt/project/dirX/dirY/dirA
/opt/project/dirX/dirY/dirB
/opt/project/dirX/dirY/dirC
where dirX/dirY
come from Working directory setting in the run configuration:
$ProjectFileDir$/dirX/dirY
.
1. Where is this behavior documented?
2. Shouldn't this be guarded by Add source roots to PYTHONPATH setting in the run configuration? I'm asking because I specifically turned this setting off as I use other means of setting PYTHONPATH
in my project and I didn't want PyCharm setting any project related directories itself. Then I was surprised PyCharm did add these directories to PYTHONPATH
nevertheless.
请先登录再写评论。
Hello,
By default, PyCharm adds /opt/project and /opt/.pycharm_helpers directories since they are essential for the correct execution of PyCharm features.
If you are using Python Console, please check if adding roots options to PYTHONPATH are enabled in Settings | Build, Execution, Deployment | Console | Python Console.
Otherwise, could you please take a screenshot of the run configuration for your file? Also, please share a dockerfile and docker-compose.yml so we can check it.