user25867259
user25867259

Reputation: 1

Efficient Python for Data Science Interactive setup with VSCode with Remote Development?

For the past two years I've been iterating my development setup. My use case for Python is data science and machine learning, meaning the Jupyter Notebook was my first choice and my primary need is to be able to quickly prototype and inspect/check my results, and only at a later stage perform a proper run. After a while I realised it was slow to type and manage cells, it doesn't force you enough to write organised code, virtual environment management is a mess, versioning is hard, you don't have Copilot and startup is slow.

I've solved all of these problems using roughly the approach described in this video: Why I stopped using Jupyter Notebooks, i.e. write using .py scripts inside VSCode and quickly prototype and check using Jupyter: Send Selection To Interactive Window when I click Shift + Enter.

Another great addition is the ability to auto-reload modules, which is effective in the Interactive Window as well, making it easy to change lines in imported modules and not having to reimport them. See this issue, tldr add this code to settings.json

"python.dataScience.runStartupCommands": ["%load_ext autoreload","%autoreload 2"]

Where is the issue now?

I've recently had to move to a remote development, but fortunately VSCode seems to transport you in the remote desktop in a matter of seconds using Remote Development using SSH and having everything as you knew.

But the caveat is that I often find myself executing a chunk of code, opening the interactive shell, do some debugging, then something at work comes up and I have to leave the workstation for 5 minutes or so, and when I come back the SSH tunnel has disconnected and this caused a reset of the interactive window, causing me to re-run everything. Usually it's quick, but tedious, while sometimes it's also slow to execute the previous part of the code and to my knowledge there is no way to cache all the variables to a file like you can do in R.

Apparently this has been a request for a while (related SO, issue#3096, issue#3998).

Alternatively I was considering using tmux, somehow combined using ipython directly in VSCode's terminal and Run Selected Text in Active Terminal, but ipython is not nearly the same experience of the VSCode interactive window. tmux would also make it easier to jump back to the same status the following day, saving a lot of setup time, but so far I didn't manage to replicate the same experience.

What is a setup that takes into account quick debugging and prototyping in the interactive fashion, in VSCode Remote Development, while retaining sessions between a day and the next? (or the coffe breaks)

Upvotes: 0

Views: 145

Answers (0)

Related Questions