kylebarron / stata_kernel

A Jupyter kernel for Stata. Works with Windows, macOS, and Linux.
https://kylebarron.dev/stata_kernel/
GNU General Public License v3.0
262 stars 55 forks source link

Running Stata code from VSCode #397

Open hozdenoren opened 2 years ago

hozdenoren commented 2 years ago

Now that the VSCode supports Jupyter kernels (at least in the insider's edition), I was wondering if it would be possible to leverage it to use Stata in VSCode via stata_kernel as we do in Atom?

amichuda commented 2 years ago

That's already been working for a while now. At least in my experience, you just need to set the stata kernel and everything works pretty straightforwardly.

kylebarron commented 2 years ago

Last time I looked, Vscode really only supported Python kernels, and it only supported a cell interface, in contrast to a line-based interface like Hydrogen, so I never used it. It would be great to have a pull request to add documentation about how to use in Vscode.

hozdenoren commented 2 years ago

@amichuda Do you mean it is working in Jupyter Notebooks within Vscode? I was wondering if it could also work like Atom with directly using do-files, getting in-line results and plots pane.

@kylebarron The insiders build supports other language kernels than Python. Based on @amichuda's response, I think this also includes stata_kernel as well. And, I agree it would be nice to have it in the docs. For example, as of now, I am having issues getting it to work within Vscode, even though it works with JupyterLab-- but there is nowhere to look for help.

amichuda commented 2 years ago

@hozdenoren if you mean, whether it will work like Hydrogen, then no. it won't inline. But it does work within the standard vscode-jupyter experience, where you get a jupyter notebook interface. There's also the option of using the interactive window, so you can use scripts directly, but it's not implemented for non-python languages, although there is a pull request open to allow for code-cells on a per-language basis (https://github.com/microsoft/vscode-jupyter/pull/4876), but it still hasn't been merged.

Does that make sense? If you're having trouble having it work, shoot me a message. If it seems like it would be useful, I can write up a short doc

kylebarron commented 2 years ago

I think you could make a vscode.md doc here: https://github.com/kylebarron/stata_kernel/tree/master/docs/src/using_jupyter

hozdenoren commented 2 years ago

@amichuda Yes, that makes sense! Thanks for the responses! I will message you the issue that I have, not to clutter here. Maybe it could be useful for writing the doc.

stevenlis commented 2 years ago

Hi, @kylebarron Is this anywhere to set the output font size in a jupyter env? I am using vscode now and something the results were wrapped and not very readable. It seems like all long results are wrapped and no horizontal scroll can not be triggered, which is something has been happening in Jupyter Lab as well.

stevenlis commented 2 years ago

@kylebarron Is there a known issue. It seems like plots won't show up in vscode: image

kylebarron commented 2 years ago

You're welcome to look into it and make a Pull Request.

stevenlis commented 2 years ago

@kylebarron seems like this is a Stata 17 related issue https://github.com/kylebarron/stata_kernel/pull/394 Sorry I forgot to mention I use Stata 17.

hozdenoren commented 2 years ago

Graphs work for me with Stata17 after I updated with the files in the PR.

On Mon, Jul 19, 2021, 21:46 StevenLi-DS @.***> wrote:

@kylebarron https://github.com/kylebarron seems like this is a Stata 17 related issue #394 https://github.com/kylebarron/stata_kernel/pull/394 Sorry I forgot to mention I use Stata 17.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kylebarron/stata_kernel/issues/397#issuecomment-882775580, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSNNL3WEXPEJ5DUA5KBZLLTYRXI3ANCNFSM5AJGCLRQ .

ledwindra commented 2 years ago

Hi everyone,

I don't know if anyone wants to see this but it appears that we not only can execute Stata from VSCode, we can also run it on GitHub remote server using Codespaces. At least using Stata 15 works for me. Thank you @kylebarron for making this library. Really cool!

image

jiawen1998 commented 2 years ago

Hi everyone,

I encountered a very weird problem with Stata kernel using jupyter from VSCode. If I use Stata kernel and Stata cell language mode at the same time, I can't execute any commands. 86c49bca5b2983704ebd80b25147066 But if I use Stata kernel and Python cell language mode, it works. b50104b9c50f254f083fb4f0bbb705d

Does anyone have any idea why it could happen?

Other information:

  1. stata version 15 4e959ad55ef2a996bb21eed89e4e4c0
jiawen1998 commented 2 years ago

Hi everyone,

I encountered a very weird problem with Stata kernel using jupyter from VSCode. If I use Stata kernel and Stata cell language mode at the same time, I can't execute any commands. 86c49bca5b2983704ebd80b25147066 But if I use Stata kernel and Python cell language mode, it works. b50104b9c50f254f083fb4f0bbb705d

Does anyone have any idea why it could happen?

Other information:

  1. stata version 15 4e959ad55ef2a996bb21eed89e4e4c0

Also, I find that variables are not appropriately displayed.

amichuda commented 2 years ago

Not a developer, but I think since the stata kernel is technically installed within your python environment, you need to have python chosen to actually run the stata. When you choose stata, it just highlights the code, but there's no actually kernel associated with it

jiawen1998 commented 2 years ago

Not a developer, but I think since the stata kernel is technically installed within your python environment, you need to have python chosen to actually run the stata. When you choose stata, it just highlights the code, but there's no actually kernel associated with it

Thank you for your reply! But in both situations, I choose the same Stata kernel, the only difference is the cell language mode. And from other posts, I think if it works normally, I can see the variables that are loaded. But when I use Stata kernel and python language mode, it works but does not display variables in the sidebar. ee73091ebf7ce007ec492f0461b0377

kylebarron commented 2 years ago

But if I use Stata kernel and Python cell language mode, it works.

To me, that says that VSCode still might not really support Jupyter kernels in languages other than Python. Under the hood, Stata Kernel uses Python with a special "entry script". So when you're looking at a Python file, VSCode probably suggests all environments that run using a Python executable.

Not sure how this works in VSCode, but in Atom there had to be an agreement between the syntax highlighting package and the code running package on the name of the language. I.e. maybe there's something in either the jupyter package or the stat syntax highlighting package in VSCode that needs to change to tell vscode "this language can be used with this jupyter kernel".

kylebarron commented 2 years ago

but I think since the stata kernel is technically installed within your python environment, you need to have python chosen to actually run the stata

This shouldn't really be the case. It's true that the stata kernel runs on top of Python, but it presents itself to Jupyter as an entirely different language. So it's probably VSCode not understanding that Stata the syntax highlighter and Stata the jupyter kernel are the same and should be used together.

kylebarron commented 2 years ago

does not display variables in the sidebar

I have no idea how that works in vscode, and it's certainly not implemented in Stata kernel. So an empty variable display is probably expected

jiawen1998 commented 2 years ago

Thank you for your clarification! I tried again this morning and find that it works with Stata kernel and Stata language this time. My friends also have similar problems with using stata kernel and stata language mode. Sometimes it works and other times it doesn't and must use stata kernel and python language mode.