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

Installing IPyStata for Stata 14 64-bit on Windows 10 & Anaconda3 (64-bit) #39

Open
dfdthor opened this issue Oct 4, 2019 · 11 comments

Comments

@dfdthor
Copy link

dfdthor commented Oct 4, 2019

%%stata
display "Hello, I am printed in Stata."

produces


com_error Traceback (most recent call last)
C:\Users\Public\Anaconda3\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
88 try:
---> 89 IDispatch = pythoncom.connect(IDispatch)
90 except pythoncom.ole_error:

com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

com_error Traceback (most recent call last)
in
----> 1 get_ipython().run_cell_magic('stata', ' ', 'display "Hello, I am printed in Stata." \n')

C:\Users\Public\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2356 with self.builtin_trap:
2357 args = (magic_arg_s, cell)
-> 2358 result = fn(*args, **kwargs)
2359 return result
2360

<C:\Users\Public\Anaconda3\lib\site-packages\decorator.py:decorator-gen-127> in stata(self, line, cell, local_ns)

C:\Users\Public\Anaconda3\lib\site-packages\IPython\core\magic.py in (f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):

C:\Users\Public\Anaconda3\lib\site-packages\ipystata\ipystata_magic.py in stata(self, line, cell, local_ns)
318 time.sleep(0.5)
319 self.log_dict[session_id] = os.path.join(self.lib_dir, 'log%s.txt' % session_id)
--> 320 self.session_dict[session_id] = win32com.client.Dispatch("stata.StataOLEApp")
321 self.do_dict[session_id] = self.session_dict[session_id].DoCommandAsync
322 self.session_dict[session_id].UtilShowStata(1)

C:\Users\Public\Anaconda3\lib\site-packages\win32com\client_init_.py in Dispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx)
93 """
94 assert UnicodeToString is None, "this is deprecated and will go away"
---> 95 dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
96 return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
97

C:\Users\Public\Anaconda3\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch, userName, clsctx)
112 else:
113 userName = str(userName)
--> 114 return (_GetGoodDispatch(IDispatch, clsctx), userName)
115
116 def _GetDescInvokeType(entry, invoke_type):

C:\Users\Public\Anaconda3\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
89 IDispatch = pythoncom.connect(IDispatch)
90 except pythoncom.ole_error:
---> 91 IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
92 else:
93 # may already be a wrapped class.

com_error: (-2147221005, 'Invalid class string', None, None)

@dfdthor
Copy link
Author

dfdthor commented Oct 4, 2019

import ipystata
from ipystata.config import config_stata
config_stata('C:/Program Files (x86)/Stata14')

executes without error and the above error occurs after restarting the kernel

@dfdthor
Copy link
Author

dfdthor commented Oct 4, 2019

C:\Program Files (x86)\Stata14>ls
ado docs STATA.LIC vcomp100.dll
auto.dta isstata.140 StataMP-64.exe
DLXAPI32.DLL Microsoft.VC90.OPENMP StataMP-64_old.exe
DLXAPI64.DLL stata.html utilities

C:\Program Files (x86)\Stata14>StataMP-64.exe /Register

C:\Program Files (x86)\Stata14>

ran without error as the the import ipystata bit and restarting the kernel.

get_ipython().run_cell_magic('stata', '-o car_df', 'sysuse auto.dta')

still gives

UsageError: Cell magic %%stata not found.

@huozi07
Copy link

huozi07 commented Aug 4, 2020

the same for me, anyone dealt with it?

@TiesdeKok
Copy link
Owner

@huozi07 let's see if we can figure out what is wrong. Some questions:

  1. Are you running this in a jupyter notebook / lab session?
  2. What is the exact code that you are executing in the notebook? A screenshot would be helpful here.
  3. Do you have Stata installed on your computer or are just running it directly via the exe?
  4. Does the batch mode work?

@karajimys
Copy link

The same for me, any ideas?
image

@karajimys
Copy link

stata installed, batch mode works

@TiesdeKok
Copy link
Owner

@karajimys this is not necessarily a problem with ipystata, it is more likely a problem with win32 not being able to run/find Stata.

I assume you get the same error if you run the below in a Jupyter Notebook?

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

@karajimys
Copy link

@TiesdeKok thank you for the answer. Yes exactly the same error.
Any ideas on how could this be solved?

@TiesdeKok
Copy link
Owner

Ok, that implies that the register step wasn't successful. Did you try to follow the registration steps (https://www.stata.com/automation/#createmsapp) but with an elevated command prompt (i.e. right click on CMD and click "run as administrator")?

@Gehrmanm
Copy link

image
help!this question ,how can i deal it

@XksA-me
Copy link

XksA-me commented Jun 13, 2023

This method solves my problem. It should be a user permission problem, and /Register operation should be performed with administrator permission. I hope it will be helpful to the people behind.

  • Method 1: Create a new cmd/powershell with administrator privileges, and then execute: "C:\Program Files (x86)\Stata15\StataSE-64.exe" /Register .

  • Method 2: Create a StataSE-64.exe shortcut, right-click-properties-target set "C:\Program Files (x86)\Stata15\StataSE-64.exe" /Register, and then right-click to run with administrator privileges.

thanks @TiesdeKok https://www.stata.com/automation/#createmsapp
image

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