poidstotal / stataRun

Provide a Visual Studio Code extension to run code(.do, .ado and command from) for Visual Studio Editor
25 stars 8 forks source link

Not working on Windows 10 x64 with Stata IC v15.1 #6

Closed ljwright closed 4 years ago

ljwright commented 5 years ago

Hi,

Thanks for writing this extension. I'm having an issue.

I installed stataRun on my Windows 10 PC (x64 Intel i5 processor). None of the stataRun commands are working, unfortunately. Each time I try I get the error message "Running the contributed command:'stataRun.runcurrent' failed", or something similar. I have Stata IC v15.1.

I changed the Paste Speed (0.1, 1, 10) and Stata Path settings but still isn't working. Do you know what I can do?

Thanks,

Liam

poidstotal commented 5 years ago

Hi This extension has NOT been tested on windows, I was hoping someone could look into the code and adapt it to windows platform. Sorry!

ljwright commented 5 years ago

Hi,

No problem. Would like to help, but don't have the programming background, sorry!

Best wishes,

Liam

Najsztub commented 5 years ago

Hey,

After struggling with running the extension on Win10 for some time I've found a solution. But it ain't pretty...

It basically follows the original Atom stata-exec building manual with some modifications for code.

  1. Install the runStata package. I also recommend the Stata Enhanced package for code highlighting.

  2. Install Node. The original instructions indicated to install this specific version of Node with default settings. I followed the instructions and haven't tried it with other versions.

  3. The stataRun extension needs a module called wimax to be compiled into a binary file. To do this Node needs windows-build-tools with Python2.7 and Visual Studio compiler packages. The installation takes some time (over 20 min. in my case) and couple of GB of disk space. To install it open up an administrator PowerShell (you can right click on the Windows icon at the bottom left and select "Windows PowerShell (Admin)") and type in:

    npm install --global --production windows-build-tools

    In my case the original command ended with an error, so I used this one with success:

    npm install --global --production windows-build-tools@2.2.1
  4. Open up Command Prompt (type cmd in the search bar in the dock, and it will be the first result) and type in:

    cd %USERPROFILE%\.vscode\extensions\yeaoh.statarun-1.1.8
    npm install winax --python=%USERPROFILE%\.windows-build-tools\python27\python.exe

    In VSCode go into Help -> About. From there save the Electron version. In the next command replace ELECTRON_VERSION with the version from the About dialogue.

    npm rebuild winax --runtime=electron --target=ELECTRON_VERSION  --build-from-source
  5. Link the Stata Automation library. The following steps worked for me on Windows 10. The Stata executable is most likely in the folder C:\Program Files (x86)\Stata15.

    1. In the installation directory, right-click on the Stata executable, for example, StataSE.exe. Choose "Create Shortcut".
    2. Right-click on the newly created "Shortcut to StataSE.exe", choose "Property", and change the Target from "C:\Program Files\Stata13\StataSE.exe" to "C:\Program Files\Stata13\StataSE.exe" /Register. Click "OK".
    3. Right-click on the updated "Shortcut to StataSE.exe"; choose "Run as administrator"

    While you're doing that, add the path of the Stata executable to the "Stata Path" option in the settings.

  6. In the %USERPROFILE%\.vscode\extensions\yeaoh.statarun-1.1.8 folder edit the sendCode.js file with the following mods:

    Lines 46 & 47 from:

    var winaxPath = os.homedir();
    winaxPath += "/.atom/packages/stataRun/node_modules/winax";

    to:

    var winaxPath = vscode.extensions.getExtension("Yeaoh.stataRun").extensionPath;
    winaxPath += "/node_modules/winax";

    I also changed line 72 from:

    const child = spawn(config.get('stataPath'), [text], {

    to:

    const child = spawn(config.get('stataPath'), [], {
  7. Restart code and enjoy executing Stata code from code! (I hope...).

Hope that this solution works for you. In case it doesn't, please feel free to write.

I also did some modifications for the extension execution itself. I will include the changes in a pull request.

Best, Mateusz

jackwynne commented 5 years ago

Thanks @Najsztub for all your work. In step 4 I get an error when trying to do a rebuild for electron version 4.2.5. Do you know if there is there some part of the log file I should be looking at to try and fix this?

Edit: I think this could be the relevant part?

gyp ERR! build error gyp ERR! stack Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23) gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at ChildProcess.emit (events.js:191:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) gyp ERR! System Windows_NT 10.0.18362 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\jack.vscode\extensions\yeaoh.statarun-1.1.8\node_modules\winax gyp ERR! node -v v7.4.0 gyp ERR! node-gyp -v v3.4.0 gyp ERR! not ok

crysjia commented 4 years ago

I am facing the same problem. When I execute the code. It shows the warning:

Running the contributed command: 'stataRun.runAll' failed.

My platform is Win10 1903, StataMP 15.1.

poidstotal commented 4 years ago

Hi, i'm very sorry... As said in the description this extension haven't been tested for windows. I was hopping someone can volunteer to adapte the code to get it work on window.

Najsztub commented 4 years ago

Dear @crysjia and @jackwynne ,

Sorry for the non-response. I didn't have to use Stata for a while, but now I've returned to it and found that after updating (the package or Code) I had to redo the install of the winax package. Unfortunately using this extension under Windows requires a bit of an effort to install.

So basically what I had to do:

I already had done npm install --global --production windows-build-tools@2.2.1

  1. I updated Node.js on my computer to the newest version..

  2. Version of the package has changed so I had to cd %USERPROFILE%\.vscode\extensions\yeaoh.statarun-2.0.3.

  3. After the update I had to reinstall wimax using npm install winax --python=%USERPROFILE%\.windows-build-tools\python27\python.exe

  4. Then I run npm rebuild winax --runtime=electron --target=ELECTRON_VERSION --build-from-source with ELECTRON_VERSION as 12.4.0 (Node.js for my Code install).

Unfortunately that wasn't enough and I kept getting NODE_MODULE_VERSION error on run. I've found a solution of a similar issue here.

So! I run the following

npm i -D electron-rebuild
npm i
node_modules\.bin\electron-rebuild -v 6.1.2

The 6.1.2 is the VSCode Electron version from the About window.

Finally I once again run npm rebuild winax --runtime=electron --target=12.4.0 --build-from-source.

And I finally got the extension up and running again.