comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

tuple error

Open theobinomy opened this issue 8 years ago • 12 comments

I'm running python 3.6 through spyder and trying to run comtypes to control SAP2000. I keey getting this error

File "E:\pyth2\lib\site-packages\comtypes_init_.py", line 659, in call_with_inout if len(outargs) == 1: # rescode is not iterable

AttributeError: 'tuple' object has no attribute 'ctypes_from_outparam'

I have tried modifying the code with the 'try/except' block that comes up as the easy solution to this problem, but no change yet. Any suggestions? Thank

theobinomy avatar May 10 '17 15:05 theobinomy

I get the error when using this bit of code: [FrameName1, ret] = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, FrameName1, 'R1', '1', 'Global') and FrameName1 = ' '

theobinomy avatar May 11 '17 15:05 theobinomy

This has been fixed on master. The quickest solution is to run the code from source. I'll try to put out a release with the fix in the coming week.

cfarrow avatar May 11 '17 15:05 cfarrow

I have just downloaded the master and replaced the comptypes folder. I'm sorry, I don't know how to run it from 'source'

This is the error I get now. Basically the same thing. I'm attaching the model file as well. 'Global' is the coordinate location. Is that throwing it off?

File "C:/Users/seanm/Desktop/0_Shortcut/Seanspdfs/struct/Struct/model2.py", line 97, in [FrameName1, ret] = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, FrameName1, 'R1', '1', 'Global')

File "E:\pyth2\lib\site-packages\comtypes_init_.py", line 659, in call_with_inout if len(outargs) == 1:

AttributeError: 'tuple' object has no attribute 'ctypes_from_outparam'

FYI: line 381 in init.py and similar is throwing an 'invalid syntax' error except COMError, err: model2 .txt

theobinomy avatar May 11 '17 16:05 theobinomy

@theobinomy copying source code from master to Python 3.6 will not work because comtypes setup.py makes 2to3 fixes on-the-fly (if nothing changed). So you need to check out master branch and run python setup.py install. It's not just copying.

vasily-v-ryabov avatar May 11 '17 19:05 vasily-v-ryabov

@vasily-v-ryabov Thanks for the heads up about the 2to3. That might explain why the fixes I tried on this haven't worked out. I'm running a windows machine at work, and am pretty new to this, so I'm not sure about pulling a master branch.

Also, I'm doing "pip install comtypes" does this do the 2to3 conversion?

theobinomy avatar May 11 '17 22:05 theobinomy

@theobinomy pip install comtypes does 2to3 fixes, but it's for release only. You can download master branch as a ZIP: https://github.com/enthought/comtypes/archive/master.zip Just unpack and run python setup.py install.

vasily-v-ryabov avatar May 12 '17 09:05 vasily-v-ryabov

thanks again @vasily-v-ryabov I downloaded the master, python setup.py'ed. The program did get further this time, but still isn't doing the magic. It created a .egg folder. I copied comtypes from there into the site-packages folder.

File "E:\pyth2\lib\site-packages\comtypes\client_init_.py", line 17, in import comtypes.automation

File "E:\pyth2\lib\site-packages\comtypes\automation.py", line 9, in from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR, COMMETHOD, COMError

ImportError: cannot import name 'IUnknown'

theobinomy avatar May 12 '17 19:05 theobinomy

python setup.py install should copy all necessary converted files into site-packages folder. Also make sure you're running it as Administrator (just in case). Try to clean-up site-packages\comtypes\* and re-install using python setup.py install only.

vasily-v-ryabov avatar May 12 '17 19:05 vasily-v-ryabov

Thank you for the guidance @Vasily I have it running now using the comtypes master.

theobinomy avatar May 18 '17 05:05 theobinomy

@vasily-v-ryabov didn't work for me, even after manually installing via python setup.py install from master, the following error keeps appearing: ImportError: cannot import name 'IUnknown' from 'comtypes' (unknown location)

(

~\anaconda3\lib\site-packages\comtypes\automation.py in <module>
      8 from ctypes import _Pointer
      9 from _ctypes import CopyComPointer
---> 10 from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR, COMMETHOD, COMError
     11 from comtypes.hresult import *
     12 from comtypes.patcher import Patch

ImportError: cannot import name 'IUnknown' from 'comtypes' (unknown location)

)

any ideas?

macsunmood avatar Apr 10 '22 16:04 macsunmood

Hi @macsunmood sorry for late reply. Is it reproduced with comtypes==1.1.11? Also please provide Python version (including 32-bit or 64-bit) in such cases.

vasily-v-ryabov avatar Aug 06 '22 06:08 vasily-v-ryabov