Skip to content
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

Running Stata code from VSCode #397

Open
hozdenoren opened this issue Jul 13, 2021 · 20 comments
Open

Running Stata code from VSCode #397

hozdenoren opened this issue Jul 13, 2021 · 20 comments

Comments

@hozdenoren
Copy link

hozdenoren commented Jul 13, 2021

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
Copy link

amichuda commented Jul 13, 2021

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
Copy link
Owner

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
Copy link
Author

@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
Copy link

@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 (microsoft/vscode-jupyter#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
Copy link
Owner

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

@hozdenoren
Copy link
Author

@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
Copy link

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
Copy link

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

@kylebarron
Copy link
Owner

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

@stevenlis
Copy link

@kylebarron seems like this is a Stata 17 related issue #394 Sorry I forgot to mention I use Stata 17.

@hozdenoren
Copy link
Author

hozdenoren commented Jul 19, 2021 via email

@ledwindra
Copy link

ledwindra commented Aug 21, 2021

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants