stata_kernel
stata_kernel copied to clipboard
stata_kernel and WSL
Problem description
I am currently trying to get stata_kernel run inside WSL, communicating with Stata under Windows. To be more precise:
- I have a working Stata 13 installation under Windows 10 1803
- I have an Ubuntu WSL distribution installed which contains my entire developer setup As I want to use my unix environment for coding, I wanted to integrate my Stata into that and stata_kernel is particularly nice for that. I have an additional full Jupyter Lab stack under Windows which works perfect with Stata. So it seems everything under Windows is properly setup. Now, when I start a Jupyter Lab server inside WSL, the stata Kernel does not seem to work. For the stack trace see below. It seems that pexpect is not properly invoking the stata session. If I run a Stata command manually it works, e.g.
/PATH/TO/STATA/StataMP-64.exe /b /PATH/TO/SOME/file.do
The do-file is properly executed and a corresponding file.log is created which contains the entire and correct stata output. Additionally, when the stata kernel starts, a blank instance of Stata opens which is doing nothing (no file executed).
I know the setup sounds rather particular, but I am absolutely unwilling to code under Windows and switching between different environments is rather tedious. I would appreciate any help.
Hello! I just wanted to reply and apologize that I will not be able to look into this for a bit. Kyle (main developer) asked me to take a more active role in looking over this repo. Normally I would try to help, but I will be on vacation for the next several weeks. To debug, I will try to install Ubuntu WSL and Stata on Windows and try to duplicate, but I will not be able to do that until I get back.
Anyway, I just wanted to let you know. I hope you find a way to continue with your workflow!
I don't think what you're trying to do is possible. When you install Stata-kernel under WSL, it understands the operating system to be Unix, and tries to start a console session of Stata. That doesn't exist on Windows, so running stata does nothing. In order to connect with the Windows Stata, it would have to use Windows-specific API functions that it can't see because it's running under Unix.
The only workaround is to have a separate installation of Stata for Unix installed within WSL.
Thanks for your quick reply. I see the point, that it stata_kernel is installed under WSL it understands Unix and not Windows. But due to the high integration of WSL, which is already achieved, I think this should still be possible. I can easily run and control the Windows Stata from within Python under WSL. E.g.
import subprocess
subprocess.call(["/PATH/TO/STATA/stata.exe", "-e", "file.do"])
is working just fine. Not sure how you are calling Stata but I would assume anything similar to this. I thought about the workaround myself but it has other challenges to overcome.
Just opening Stata isn't enough. The kernel doesn't just run scripts. You need to be able to communicate with the COM interface, aka be able to use the win32com Python package, and I don't think that's possible.
@FHeidemann I think we need Stata to supply a working version of "Stata for Linux" that can be installed on WSL. With the same Stata14 tarball, I managed to get stata installed for Linux machines (running Linux Mint distro) but not on WSL nor WSL2. I get the same error message:
stata: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
Though, things are working fine on a standard Linux machine.
@llinfeng I have the same error message on my local Linux machine for a while, btw. I fix the issue by linking libncurses.so.5. This is what I did when I installed on my machine:
sudo ln -sf /usr/lib/libncursesw.so.6 /usr/lib/libncursesw.so.5
sudo ln -sf /usr/lib/libncursesw.so.6 /usr/lib/libncurses.so.5
sudo ln -s /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5
@llinfeng @mcaceresb In the meantime, I installed and currently use a stata 13 instance. I do neither have a problem with the library nor do I have the ncurses library at all under WSL. Stata does not seem to use it (at least in version 13), I guess.
@FHeidemann That is very interesting. The issue that I have is precisely with Stata 13 (albeit not the graphical version).
@mcaceresb I have to correct myself. I checked again and I do have the lib installed but located at /lib/x86_64-linux-gnu/libncurses.so.5.
@FHeidemann Thank you for the path info. Here are commands that revived Stata 14 on both WSL (Pengwin) and WSL2 (Ubuntu).
sudo ln -sf /lib/x86_64-linux-gnu/libncurses.so.6 /usr/lib/libncurses.so.5
sudo ln -sf /lib/x86_64-linux-gnu/libncursesw.so.6 /usr/lib/libncursesw.so.5
sudo ln -sf /lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/libtinfo.so.5
And, many thanks to @mcaceresb for pointing out what was going wrong with the libncurses.so.5 error.