Jump to content

xlwings - pywin32 Python package installation


---
 Share

Recommended Posts

Hi, 

I've been trying for a while to install the xlwings python packages, which requires the 'pywin32' python packages, but I have never been successful. 

I'm getting an "ModuleNotFoundError: No module named 'pywintypes'" error when importing the xlwings module. 

This apparently has something to do with pythoncom3x.dll and pywintypes3x.dll which are not installed to the correct location. 

I'm using this module to interact directly with Excel (export measurement results, amongst other things).

For the moment I'm using a standalone python installation where I install these Python modules +  a RPC Server module, but this in the end not so nice and maintainable. 

Any help to install the xlwings module within the GOM scripting environment would be greatly appreciated ! 

 

 

Link to comment
Share on other sites

I'm a python novice so take my advice for what it is worth. There are a lot of things I just simply do not understand how python works.

I got our reports to autoprint by installing pywin32 which is the python package needed to communicate with windows API. It is known as win32api, but for some crazy reason you must install pywin32 instead. I installed this thru the command prompt as well as using GOM's script which is pre-installed in the 'tools' section of the scripts.

In the command prompt I typed in:

pip install pywin32

Then I installed pywin32 using the script inside GOM under the tools section that allows you to install python packages to what I think it the GOM package installation directory. So you bring this scripts up in the right pane and right click > run, then enter 'pywin32' into the box. That should install it into the GOM directory, 'I think'

At the top of my script I then used this line:

from win32 import win32api

Now, for some crazy reason this came up with a dll error. So I had to take the 2 dll files located in this directory C:\Users\Owner\AppData\Local\Programs\Python\Python310\Lib\site-packages\pywin32_system32 and copy them into the C:\Windows\System32 folder

Good luck. Since Gom is it's own python deal, that works without having Python installed on the computer, I don't know what folder it is looking for when I use the line 'from win32...'  Is it looking in the GOM roaming python directory or is it looking at the local installed python directory on the computer, or perhaps is it looking in the C:\Windows\Syste32 folder? It is all confusing to me, but I know I got it to work by doing the above.

 

 

 

 

 

Edited
Link to comment
Share on other sites

Hi Tim,

Thanks for your answer. 

I tried in the past to copy the 2 DLL files you mentioned to different locations without any luck, but now it worked in software version V2022 for some reason 🙂

The only difference I can think of is that I now first tried to install the pywin32 module, before the xlwings module... Anyways, thanks for the help ! 🙂 

FYI: to print reports, you can try the line of code below. This doesn't require any special packages. It will open the pdf file, print it to the default printer, and close the file again. 

####

import os
os.startfile(pdf_filename, "print")

 

Kind regards,


François

Link to comment
Share on other sites

Glad you got it working, thanks for that simplified autoprint code, mine is rather short, but nothing close to that short...I'll see how well it works for me and will probably replace all our code to keep thing simple.

I installed 2022 this weekend, and had to re-learn exactly what dll's I had to toss into the system32 folder. It wasn't the the below dlls that I had to copy and paste into the system32 folder:

C:\Users\Owner\AppData\Local\Programs\Python\Python310\Lib\site-packages\pywin32_system32

It was actually the two dlls inside this folder that I had to copy into the system32 folder:

C:\Users\Owner\AppData\Roaming\GOM\2022\gom_python_caching\pywin32-304-cp39-cp39-win_amd64\pywin32_system32

In 2022, I had to right click the 'User-defined scripts' and select the 'Install Python Package...' and inside that mini-program I entered 'pywin32'....that installs the pywin32 package into the Roaming gom directory above and that is where the dlls need to be found.

When I forget for 2023, I'll revisit this thread, lol.

Cheers!

Link to comment
Share on other sites

  • 5 months later...

Having the same issue but in ATOS Professional 2020. I have copied the (2) dll files located in C:\Users\Administrator\AppData\Roaming\gom\2020\python\pywin32_system32 named pythoncom37.dll and pywintypes37.dll into the system32 folder but it does not appear to have made any impact. Is there something additional to be done or is this the only known solution to this problem?

Link to comment
Share on other sites

 Share

×
×
  • Create New...