win32com error

1,155 views
Skip to first unread message

steven laycock

unread,
Jun 23, 2017, 12:39:07 PM6/23/17
to thonny
Hi

I'm looking to get to grips with Python by having a go a translating some Word VBA macros I've written.  However I seem to have fallen at the first obstacle.

I have installed python 3.6.1 32 bit and separately pywin 32 bit on a windows 10 64 bit installation (with Office 2016 64 bit)

I have a very simple script which just opens Word.  But it doesn't work.


Import win32com.client as win32

MSWord=win32.Dispatch("Word.Application")
MSWord.Visible = True

Gives the error

%Debug Wordtest.py
  File "G:\Download\Python\scripts\Wordtest.py", line 1
    Import win32com.client as win32
                  ^
SyntaxError: invalid syntax (where the ^ is actually under the m of com)

Is the answer as simple as using 64 bit versions of python and pywin32





freeflow

unread,
Jun 23, 2017, 3:27:02 PM6/23/17
to thonny
I solved this problem as follows.

I found the instructions on installing Thonny over an existing python installation

As I had been playing around with python I realised I had a number of python installations.

I removed all python installations and IDE's from my windows (including manually purging directories)

Installed 64 bit version of python 
Installed 63 bit version of pywin32
Installed Thonny over the python installation above
Selected the above python installation as my interpreter.

No problems importing win32com

If there is a way to use win32com using the built in python interpreter please let me know.

 

Aivar Annamaa

unread,
Jun 23, 2017, 6:38:23 PM6/23/17
to thonny
Hi!

Your original error was caused by "Import" which should have been "import".

I suppose you tried to install pywin32 using the exe-installer. I'm afraid it's not possible to use this for Thonny's built-in virtual environment.
Thonny supports installing PyPI packages using pip (Tools => Manage packages or Tools => Open system shell). Confusingly, the package "pywin32" in PyPI doesn't have any downloads. On the other hand, there's a package called "pypiwin32" which can be installed by pip (see https://code.activestate.com/lists/python-win32/13613/)

Hope this helps!

best regards,
Aivar
Reply all
Reply to author
Forward
0 new messages