3

My situation is that I have set up a container in a remote server, and inside the container, there is a virtual environment. I'm using the python interpreter inside this virtual environment in this container, not the one on the host.

From my local machine, I can open up PyCharm, and use Tools->Deployment->Configuration to easily set up a remote connection. And For a specific project, I can set up the interpreter by clicking Files->Settings->Project Interpreter. However, it seems that I can only select the host Python interpreter(/usr/bin/python) on the remote server, not the one inside the virtual environment in the container. How could I set up using this interpreter?

I googled but can't find exact solution. I don't think I need to install Docker locally because my Docker is on the remote server side, right?

2
  • The virtual environment inside the container is ideally not exposed to the outside world. That being said, if your volume is shared with the host, you might be able to invoke the virtual env by going to the path where the volume of your container resides, Commented Mar 23, 2021 at 4:03
  • You can add a remote Docker interpreter in PyCharm (see here ), but it would require to make Docker listen for TCP. This isn't hard but it'll take some time. In my opinion using Docker locally will be better. Commented Mar 23, 2021 at 6:08

1 Answer 1

3

In similar way you are connecting to remote host - you would need to setup container with same capabilities e.g. set ssh server running on there. Then you should expose the port into public world or use nested ssh tunnel, which would be better alternative.

Another interesting approach (maybe recommended) is to forward Docker socket from the remote machine so, that you local Docker CLI uses this socket for sending commands to remote host. Theoretically, then you could add this container directly in PyCharm, when you set correct Docker host address there.

Further, virtual environments on other than local host systems are not supported natively by PyCharm. However, you could try to add path of python and see if it works e.g. venv/bin/python from project directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.