6

I've set up a remote Docker interpreter in PyCharm 2019.2, where I'm able to connect and run a simple Python script just fine. However, the Docker image that I'm trying to use (ros:kinetic-ros-base) makes some modifications to $PYTHONPATH in its entrypoint, which it seems PyCharm ignores/overwrites.

I can demonstrate this by printing the $PYTHONPATH variable straight from the Docker container:

$ docker run -it ros:kinetic-ros-base python
>>> import os
>>> os.environ['PYTHONPATH']
'/opt/ros/kinetic/lib/python2.7/dist-packages'

Or by using PyCharm to run a script via the remote Docker interpreter, using the same ros:kinetic-ros-base image:

import os
print(os.environ['PYTHONPATH'])
/opt/project:/opt/.pycharm_helpers/pycharm_matplotlib_backend:/opt/.pycharm_helpers/pycharm_display

Clearly PyCharm is replacing the $PYTHONPATH variable after the container's entrypoint script runs.

I can hack around this by adding /opt/ros/kinetic/lib/python2.7/dist-packages to the run configuration's Environment Variables in Edit Configurations..., but then code inspections that rely on the container's PYTHONPATH fail to resolve. The line import rospy gives the IDE error No module named rospy, though it will run just fine (obviously, the PYTHONPATH is only set on Run in this case).

Is there any way to either

  1. Get PyCharm to respect changes made to PYTHONPATH in the Docker image's ENTRYPOINT script, or
  2. Get the integrated code editor inspections to use a manually defined PYTHONPATH environment variable in the Run configuration?
Nick Faughey
  • 584
  • 1
  • 5
  • 10
  • 3
    I am having a very similar issue with yours but without using docker. I am setting a PYTHONPATH as environment variable in the Run configuration. But Pycharm is adding is own path to my pythonpath and that break the script I want to use. – Eskignax Aug 24 '19 at 09:29

0 Answers0