mattiasnordin / StataEditor

Stata Editor for Sublime Text 3
47 stars 18 forks source link

Stata 14 Automation on Windows 10 #13

Closed bryanwhiting closed 7 years ago

bryanwhiting commented 7 years ago

I've used StataEditor successfully on Windows 7, Stata 13. Upgrading to Windows 10, I cannot get automation to work. Has this been tested?

mattiasnordin commented 7 years ago

I've used Stata 14 on Windows 10 but I would be very surprised if Stata 13 doesn't work. To check if automation is set up properly, open the console and type

import win32com.client win32com.client.Dispatch ("stata.StataOLEApp")

and let me know what the response is.

bryanwhiting commented 7 years ago

@mattiasnordin, thanks again for your help. This package is awesome.

The problem may be that I don't have Python 3.3, though I'm not sure. And I wasn't clear above - I'm now using Windows 10 and Stata 14. Previously, I was using Stata 13 on Windows 7, with Python2.7 and it worked fine.

When I open Sublime and the console, I see the following error:

reloading plugin StataEditor.CompletionsPlugin
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 109, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 915, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "CompletionsPlugin in C:\Users\bwhiting\AppData\Roaming\Sublime Text 3\Installed Packages\StataEditor.sublime-package", line 2, in <module>
ImportError: No module named 'Pywin32.setup'
reloading plugin StataEditor.StataEditorPlugin
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 109, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 915, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "StataEditorPlugin in C:\Users\bwhiting\AppData\Roaming\Sublime Text 3\Installed Packages\StataEditor.sublime-package", line 3, in <module>
ImportError: No module named 'Pywin32.setup'

It appears that it's just not installing properly with Sublime. I try to run "import win32com.client" and get the following error:

>>> import win32com.client
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'win32com'

I have Python27 installed on my machine. I opened Python2.7 and ran the code you pasted above, and got the following:

Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> win32com.client.Dispatch("stata.StataOLEApp")
<COMObject stata.StataOLEApp>

Stata opened just fine. Thanks again for your help!

eborbath commented 7 years ago

I have a similar problem, with exactly the same setup. For me when I press ctrl+d it opens stata but does not send the syntax. It's Stata 14 with Windows 10 and ST3. I tried the command you suggested above and I got this message:

>>> import win32com.client
>>> win32com.client.Dispatch ("stata.StataOLEApp")
Traceback (most recent call last):
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

I went through all the steps of the installation you suggested. Including installing the Pywin32 package and the automation library. I don't have a separate python distribution installed though.

Any ideas on what should I do?

mattiasnordin commented 7 years ago

bryanwhiting: In your case it looks as if Pywin32 is not setup properly, do you know if that is the case?

eborbath: This is odd. If the win32com.client.Dispatch ("stata.StataOLEApp") command doesn't launch Stata, then automation should be broken. But then you say that ctrl+d launches Stata without sending code which seems like it shouldn't happen if automation doesn't work. What message do you get in the console when pressing ctrl+d?

eborbath commented 7 years ago

when I press ctrl+d stata starts, but no code is sent. This is the message it gives me in the ST console:

Traceback (most recent call last):
  File "StataEditorPlugin in C:\Users\endre\AppData\Roaming\Sublime Text 3\Installed Packages\StataEditor.sublime-package", line 39, in StataAutomate
AttributeError: 'module' object has no attribute 'stata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 812, in run_
    return self.run(edit, **args)
  File "StataEditorPlugin in C:\Users\endre\AppData\Roaming\Sublime Text 3\Installed Packages\StataEditor.sublime-package", line 103, in run
  File "StataEditorPlugin in C:\Users\endre\AppData\Roaming\Sublime Text 3\Installed Packages\StataEditor.sublime-package", line 43, in StataAutomate
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\endre\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

I have no idea what this means though.

mattiasnordin commented 7 years ago

Alright, now it makes sense, I forgot that Stata can be launched from ST without automation working. The problem is definitely with automation. I don't know why it wouldn't work, for me nothing changed when I upgraded from Windows 8 to 10. My best guess would be to try to install the automation object once again. While it always seem best to follow the Vista instruction, maybe you could try the non-Vista one (http://www.stata.com/automation/#install)

bryanwhiting commented 7 years ago

@mattiasnordin, I had to go to Package Installer and install the Pywin32 package. Everything works now perfectly.

Also, I did both the Vista and the non-Vista automation instructions in all of my debugging, so I'm not sure which works.

eborbath commented 7 years ago

Thanks a lot! It works well for me as well.

mattiasnordin commented 7 years ago

Great!

bryanwhiting commented 7 years ago

Thanks again for the quick and useful help!

rensec commented 5 years ago

I'm having the same issue as eborbath, running Stata 14.2 on Windows 10. Stata opens, but no code is passed. From the console:

>>> win32com.client.Dispatch ("stata.StataOLEApp")
Traceback (most recent call last):
  File "C:\Users\***\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\***\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Users\***\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\***\AppData\Roaming\Sublime Text 3\Packages\Pywin32\lib\x64\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

I tried both the Vista and the regular method (using StataSE-64/Register) for installing automation. I don't get any errors when doing that, and also not when I run unregister.