enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
292 stars 97 forks source link

tuple error #126

Open theobinomy opened 7 years ago

theobinomy commented 7 years ago

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 commented 7 years ago

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 = ' '

cfarrow commented 7 years ago

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.

theobinomy commented 7 years ago

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

vasily-v-ryabov commented 7 years ago

@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.

theobinomy commented 7 years ago

@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?

vasily-v-ryabov commented 7 years ago

@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.

theobinomy commented 7 years ago

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'

vasily-v-ryabov commented 7 years ago

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.

theobinomy commented 7 years ago

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

macsunmood commented 2 years ago

@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?

vasily-v-ryabov commented 2 years ago

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.

junkmd commented 1 month ago

@macsunmood

Is there an update on this issue?