Select to view content in your preferred language

how to install pywin32 for ArcGIS Pro 3.x

2822
10
Jump to solution
10-18-2022 02:50 PM
TimWhiteaker
Frequent Contributor

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
Frequent Contributor

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
10 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
Frequent Contributor

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
Frequent Contributor

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
Frequent Contributor

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
EmmaButzler
New Contributor

Hi Tim,

I am currenlty using arcGIS pro version 3.3.1 and the package "pywin32" isn't available to add. Do you know why or any work around to get pywin32 package installed in this version.

0 Kudos
ChrisSnyder
Honored Contributor

I'm having the same issue as you Emma and Tim. Prior to updating to Pro v3.3.1 I was able to install PythonWin which also installs pywin32... and I've always installed to the base Python install. PythonWin seems to install but errors out now upon attempting to start the PythonWin IDE (error message: "The application can not locate Python39.dll (126) The specified module could not be found"). Also, perhaps more concerning, other modules I use that depend on pywin32 such as 'pyad' (Python access to MS Active Directly)  and 'win32com' (Excel) all error out now:

Python 3.11.8 (main, Mar 22 2024, 13:25:41) [MSC v.1938 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>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\win32com\__init__.py", line 8, in <module>
import pythoncom
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\win32\lib\pywintypes.py", line 126, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\win32\lib\pywintypes.py", line 52, in __import_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed while importing _win32sysloader: The specified module could not be found.

 

0 Kudos
LauraTateosian_augori
Emerging Contributor

I was able to install it in ArcGIS Pro using a pip install as follows:

1) Open the command prompt by typing “command prompt” or cmd in the Windows search.

2) Assuming your Python cloned environment is in the default location, type this command* (inserting your own username in the path): 

C:\Users\[yourUsername]\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe -m pip install pywin32

If you are not using the default location, alter the file path to where your own clone is stored.  For example, if my username is Elmer and I created a clone in this location, C:\Users\Elmer\AppData\doubletree\arcgispro-py3-myclone2, I would use this command:

C:\Users\Elmer\AppData\doubletree\arcgispro-py3-myclone2\python.exe -m pip install pywin32

3) Navigate to the file in which pywin32 has been downloaded (your cloned environment > Lib > site-packages > pythonwin)

4) Open Pythonwin.exe and try importing arcpy.

0 Kudos
TimWhiteaker
Frequent Contributor

I'm still on 3.2, where the previous solution I posted worked. If anything changes once I migrate to 3.3, I'll share results here. I think Esri prefers you to make a clone of the default environment, and add packages to the clone rather than modify the default environment.  But if you found a solution that worked, then hooray!

0 Kudos