-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved UX with Python in VS Code #170
Comments
no strong feeling on this
… Message ID: ***@***.***>
|
I know everyone is going to hate me, but I'm currently switching my teaching from VS Code to Spyder. VS Code has too many basic issues for interactive work (e.g. no IPython integration, no way to run code from a script line by line, etc.). Unless you use notebooks (which I don't), so this might not be relevant then. |
Errm no, this is not true. I don't use notebooks and I do use these features with my scripts. You need to add "code cells" by adding comments of the form,
and you get access to all interactive features without having to use a notebook. |
@hoechenberger this is using a notebook. |
No? It's a script... |
It basically starts a notebook to run the code from your script. And the you can still only run cell by cell and not line by line. |
Also, I was refering to your comment about eventually removing Spyder. This does not mean that I am against improving the UX of using VS Code with MNE. |
I don't know what you mean by saying, "basically starts a notebook"? It sends blocks or lines of code to a Jupyter (i.e., basically IPython) kernel.
It's simply not true, you can send individual lines to the interactive window. I mean I really don't care how you work or what you teach, but what you said above is simply just not true, I'm sorry... |
Let me know how I can run a single line of code and advance to the next one. |
Place the cursor on the line (or select one or more lines), bring up the command palette, and choose, "Jupyter: Run Selection/Line in Interactive Window". Can probably be mapped to a more convenient keyboard shortcut too. Doesn't advance to the next line automatically though. |
That's what I meant by running a script line by line. Without advancing, it is not useful for stepping through a script. PyCharm and Spyder can do this by default, and so does RStudio for R and VS Code (yes, the same VS Code) for Julia! So I think what I said is true. Anyway, all I wanted to say is: please don't drop Spyder. |
@cbrnr FWIW there is a keyboard shortcut, add this to [
{
"key": "ctrl+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorTextFocus"
},
] This will send the selected text (or if none selected, the line on which the cursor lies) to the active terminal. The active terminal can be running Bash, a vanilla python interpreter, an ipython interpreter, R, whatever. No notebooks involved. But as noted before, it does not auto-advance. It also kinda mangles indentation so it sometimes chokes on multiline selections (I think when there are both indents & later outdents is when it fails) and IIRC it sends physical lines not logical (python statement) lines |
Yes, I tried that among many other things. Bottom line is that VS Code is not a good editor for interactive Python (non-notebook). |
@cbrnr I don't know why you say this. See: Screen.Recording.2023-02-14.at.21.49.45.mov |
I'll take it back. It is just not for my workflow, where I really need to be able to run single lines or blocks of code and then the cursor auto-addvances to the next executable line. Not cell. |
Hey all, sorry this escalated in the way it did; this was unnecessary, and I recognize my (negative) contribution in the process. I just had a brief private chat with @cbrnr, and we're cool (again). Apparently, there are use cases for Spyder, so let's just keep including it in our installers as long as it doesn't cause too much of a burden. My proposal to remove it was really just more of a thought experiment, no immediate call for action. Have a great day, everybody! |
I also apologize for taking this thread in the wrong direction by statements that could be easily misinterpreted. I know my communication style is very direct (we've had this conversation before), but my intention is not to attack or insult anyone. If anyone feels attacked or insulted, I'd be happy to chat. |
I'm not sure we can -- if you install on Linux, macOS, or Windows, you get a nice start menu / app folder shortcut. I bet 95%+ of people launch We could add a little note that, as an alternative to setting the config value, you could always launch vscode from a terminal already configured to find the correct
Agreed we should do this in MNE-installers. Without too much effort we could probably even add a little error prompt when
No idea on Windows... |
Wait wait wait what? This should not be necessary. If you need to do this, could it be you missed this setup step? https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line If we cannot find |
Yes because all I did was download the |
I believe I actually got a prompt when first starting VS Code on macOS. But I don't remember. Anyway, like I said, we could just tell users what to do in case we cannot find |
This has now been implemented in the latest release of the Python for VS Code extension (albeit it's still an experiment): https://devblogs.microsoft.com/python/python-in-visual-studio-code-november-2023-release/ |
Yes, and I'm already using and loving it! I would still wait until this is not experimental. And there is one final big one: IPython support is still not implemented. They have been discussing this (in various issues), but unless it is possible to use IPython instead of the standard interactive Python interpreter, I still would not use VS Code instead of Spyder in our installers. |
Is that still the case for you? |
I never actually switched my teaching to Spyder, because it is too much effort and probably not worth it 😄. Things have improved a little meanwhile, because Smart Send is now enabled by default. There are still a couple of bugs and quirks that make the experience less than ideal. However, I'll probably stick with it and just hope that VS Code keeps improving (for example, the new interactive console experience might be worth looking into once it gets out of beta). IPython will likely never be integrated, but that's OK as long as there are decent alternatives, which I think are almost there. |
Then maybe my above proposal could actually work: we launch vs code from an activated MNE-Installer environment. It will then automatically pick up and activate that environment (at least by default) we can easily add a shortcut for this (and display an informative error message if the "code" command cannot be found) |
With the latest Python extension, VS Code -- when started from the command line -- will honor the conda environment that was active in the shell VS Code was started from:
https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2023-release/#automatic-environment-selection-when-vs-code-is-launched-from-an-activated-terminal
We could make use of this new feature and essentially drop the VS Code setup instructions from the MNE installers docs:
https://mne.tools/stable/install/installers.html#vs-code-setup
We could take it even further and add something of a menu entry / icon that would start a terminal, activate the MNE environment, and run VS Code from there. However it would still require the user to first install VS Code on their system. But I think it would make VS Code use easier! Users could just click on "VS Code (MNE)" and would have MNE in VS Code up and running. Aaaaand, we could then drop Spyder, eventually... 😈
What do you think?
@larsoner @agramfort @drammock
The text was updated successfully, but these errors were encountered: