r/Python • u/aplavin • Aug 26 '18
Remote Python & IDE workflow?
Hi! I'm looking for a way to use a remote Python interpreter (in my case it's a docker container on another machine) with an IDE like Pycharm or VS Code. In principle, it seems possible using just pycharm "remote interpreter" feature, althrough it requires SSH access into that container which I would prefer not to install if possible. Another major piece I have no idea how to make working is plots. I don't need interactive plots, just jupyter-style static ones will work. This sounds like a quite common usecase, but I couldn't find any help on how to set it up. For now I use jupyterlab running in that docker container, but really miss autocomplete and other stuff offered by IDEs. Any pointers welcome!
2
u/[deleted] Aug 26 '18
That sounds like a bit of a mess... is it not possible to just use a venv that matches the remote environment?
2
u/dagmx Aug 26 '18
Afaik you don't need SSH access for pycharms remote debugger. That's only for it to execute things for you.
All you need is to copy the pydevd package from pycharms bin, import it and then connect over a port. As long as there's an IP and port you should be able to connect with the remote debugger. Though you'd probably want some kind of shell access anyway.
2
u/[deleted] Aug 27 '18
Hey! I'm on the PyCharm team, let me try to help you out here.
If I understand correctly, you have a server that runs a Docker daemon, and you want to be able to run an image on that server. In turn, you want to connect to a Python interpreter within that image.
First, set up the Docker daemon to be accessible over the network. By default it listens on
/var/run/docker.sock, and you'd like it to listen on a network socket instead. You do this by editing the 'hosts' key in/etc/docker/daemon.json. Use the box's IP on the interface you'll be connecting to, for example: 'tcp://10.0.5.15:2376'. And make sure to restart Docker so it starts listening on that socket.Then, in PyCharm, just go to Settings | Build, Execution, Deployment | Docker, and connect to the Docker daemon on your server.
At this point, you should be able to launch containers using PyCharm on the remote host. See the Docker tool window for details.
I haven't done this before myself. So I'm not entirely sure what happens to published ports and how you'd need to connect to them. This will affect how things like debugging work. Let me know how things go and i'll do my best to help you out!
1
u/jacquespeeters Aug 26 '18
That's why i opted for Atom. Atom + remote hydrogen kernel + remote file sync + autoreload is a great combo. Debugging isn't good yet, therefore I open a remote console separately. With this workflow I have the flexibility of Jupyter notebooks while directly coding my project for production purpose.
1
u/13steinj Aug 27 '18
If the server is linux based, and ssh is not a deal breaker, install ssh and forward your X11 session to the server. If you are on a mac/windows machine you will need to install and start XQuartz/(XMing|VcXsrv), if you are on Linux and don't have an X server you will obviously need to install it.
You can in theory do this without SSH, but that's a severe pain in the ass to set up.
1
u/[deleted] Aug 26 '18
Editors like PyCharm aren't really designed for this kind of work. These editors emphasize "projects", i.e. some static description of what you are working on, which should control which things are exposed to you in your working environment, which options should be made available etc. This comes from thinking that, basically, "user is a moron, and needs to be protected from bad choices", which, probably, reflects the reality of people who design these tools. And, because these tools try to predict and proscribe you the "best practices", they don't try to be always correct, they try to be correct for the average case.
So, with some effort, you may find a way to interact with Python's interpreter running in a Docker container, but then some other things won't work. Like, maybe, opening files from your working environment, or maybe code intellisense etc.
I believe you would have much easier time using Python interpreter running in container, if you used Emacs or Vim. In particular, because those editors are used by people who often do need to deal with complicated setups, spread over multiple computers and operating systems.
2
u/[deleted] Aug 26 '18
I suggest that you take a look at spacemacs. It's an emacs distro, which can be converted to a good IDE with auto complete. However, it'll take some time for you to get productive with it.