how to install pywin32 for ArcGIS Pro 3.x

1903
5
Jump to solution
10-18-2022 02:50 PM
TimWhiteaker
Occasional Contributor II

How do I install pywin32 for ArcGIS Pro 3.0?  It worked for me in 2.x, but in 3.0, the installation fails whether trying it from the Pro user interface (Settings > Package Manager > Add Packages) or in a Python command prompt using conda install or pip install. There seems to be a lot of conflicts in dependency versions. After attempting to install, if I run this code:

 

from win32com import client

 

I get:

 

ImportError: DLL load failed while importing pythoncom: The specified procedure could not be found.

 

 

I'm using pywin32 and arcpy to update an APRX and an Excel file and export sheets from Excel to PDF.

 

0 Kudos
1 Solution

Accepted Solutions
TimWhiteaker
Occasional Contributor II

The solution I found:

  1. In Pro 3.0 or 3.0.2 (tested on both), clone the base environment and activate the new environment. 
  2. Add the pywin32 package.
  3. Browse to the environment folder (e.g., C:\Users\username\AppData\Local\ESRI\conda\envs\my-new-env) in an elevated Python command prompt and enter this command: python.exe Scripts/pywin32_postinstall.py -install

Now I can use pywin32. That last step was a tip I gleaned from Gohlke's wheel page.

This was done on a virtual machine. On my physical machine, the admins have some security thing going on that prevents me from installing the pywin32 package, but others may not encounter such an issue.

View solution in original post

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

Your attempts to install what is already there (at least parts of it) may have had undesireable consequences.

 

from win32com import client

dir(client)
['CDispatch', 'CLSIDToClass', 'CastTo', 'CoClassBaseClass', 'Constants', 
'Dispatch', 'DispatchBaseClass', 'DispatchEx', 'DispatchWithEvents', 'EventsProxy', 'GetActiveObject', 'GetObject', 'Moniker', 'Record', 
'VARIANT', 'WithEvents', '_PyIDispatchType', '__WrapDispatch', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', 
'__name__', '__package__', '__path__', '__spec__', '_event_setattr_', 
'_get_good_object_', '_get_good_single_object_', 'build', 'constants', 
'dynamic', 'gencache', 'getevents', 'pythoncom', 'pywintypes', 'sys']

 

Delete your clone (or reinstall Pro if you tried this in base.

>>>conda install xxxxxx --dry-run

Is a useful step to anticipate installation issues beforehand.


... sort of retired...
0 Kudos
TimWhiteaker
Occasional Contributor II

I was working in a clone. I switched back to base (arcgispro-py3) and get this in a Python command prompt.

(arcgispro-py3) C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3>python
Python 3.9.11 [MSC v.1931 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from win32com import client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'win32com'

I'm in Pro 3.0.0.  Is it possible that attempting to install pywin32 in the clone corrupted the base installation?

0 Kudos
DanPatterson
MVP Esteemed Contributor

I am using 3.0.2.

I can't remember when pywin32 stuff appeared.

Messing with the clone can't affect the base environment.

You can also look at

Welcome to PyPDF2 — PyPDF2 documentation

xlrd — xlrd 2.0.1 documentation

xlwt documentation — xlwt 1.3.0 documentation

for other options if you can resolve, they are installed by esri and I think used somewhere in the Pro ecosystem.


... sort of retired...
0 Kudos
TimWhiteaker
Occasional Contributor II

Thanks for the other things to look at but I don't think they handle exporting PDFs from Excel.

With a clean install of Pro 3.0, I upgraded to 3.0.2, and I still don't have pywin32 installed.  A search for "win" in the Package Manager in Pro reveals these libraries that seem close but not quite it:

* python-certifi-win32

* pywin32-security

For an import test, this time I tried from within a Python console window in Pro. I get "No module named 'win32com'".  I wonder how you have pywin32 but I don't.

console windowconsole window

 

0 Kudos
TimWhiteaker
Occasional Contributor II

The solution I found:

  1. In Pro 3.0 or 3.0.2 (tested on both), clone the base environment and activate the new environment. 
  2. Add the pywin32 package.
  3. Browse to the environment folder (e.g., C:\Users\username\AppData\Local\ESRI\conda\envs\my-new-env) in an elevated Python command prompt and enter this command: python.exe Scripts/pywin32_postinstall.py -install

Now I can use pywin32. That last step was a tip I gleaned from Gohlke's wheel page.

This was done on a virtual machine. On my physical machine, the admins have some security thing going on that prevents me from installing the pywin32 package, but others may not encounter such an issue.

0 Kudos