win32com.client is a module in the win32com package you need to import the actual module.

import win32com.client 

w = win32com.client.Dispatch('Word.Application')
Answer from joojaa on Stack Overflow
🌐
GitHub
gist.github.com › rdapaz › 63590adb94a46039ca4a10994dff9dbe
Fix for module win32com.gen_py has no attribute 'CLSIDToPackageMap' · GitHub
`import win32com.client as win32 from win32com.client import constants, Dispatch · excel = win32.gencache.EnsureDispatch ("Excel.Application") word = win32.gencache.EnsureDispatch("Word.Application") ` ... try: xl = client.gencache.EnsureDispatch('Excel.Application') except AttributeError: # Corner case dependencies. import os import re import sys import shutil # Remove cache and try again. MODULE_LIST = [m.__name__ for m in sys.modules.values()] for module in MODULE_LIST: if re.match(r'win32com\.gen_py\..+', module): del sys.modules[module] shutil.rmtree(os.path.abspath(os.path.join(win32com.__gen_path__, '..'))) from win32com import client xl = client.gencache.EnsureDispatch('Excel.Application')
Discussions

python 3.x - Why am I suddenly getting a no attribute 'CLSIDToPackageMap' error with win32com.client? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: module 'win32com.gen_py.00020905-0000-4B30-A977-D214852036FFx0x3x0' has no attribute 'CLSIDToClassMap'
i had try install pywin32 in a conda env, and use it by: from win32com import client word = client.Dispatch("Word.Application") and catch an error , like : Traceback (most recent call las... More on github.com
🌐 github.com
5
April 27, 2021
win32com.client issue.
I'll bet you can read this and figure out how they did it, if you can't just straight use this varunsrin/one-py/blob/master/README.md More on reddit.com
🌐 r/learnpython
4
4
May 11, 2016
Win32Com.Client error with Python 3.4 - Stack Overflow
I am working with python 3.4 and pywin32-219. And I am trying to use the win32com.client module. I get the following errors. Is there any suggestions that y'all have that will allow me to use win32... More on stackoverflow.com
🌐 stackoverflow.com
June 16, 2014
🌐
GitHub
github.com › Nuitka › Nuitka › issues › 3235
win32com package could import its sub-packages from the wrong places · Issue #3235 · Nuitka/Nuitka
December 2, 2024 - Traceback (most recent call last): File "D:\...\dist\start.dist\utils\Win32Utils.py", line 5, in dispatch File "D:\...\dist\start.dist\win32com\client\gencache.py", line 628, in EnsureDispatch AttributeError: module 'win32com.client' has no attribute 'Dispatch' Traceback (most recent call last): File "D:\...\dist\start.dist\utils\Win32Utils.py", line 19, in dispatch File "D:\...\dist\start.dist\win32com\client\gencache.py", line 628, in EnsureDispatch AttributeError: module 'win32com.client' has no attribute 'Dispatch'
Author   Nuitka
🌐
Narkive
python-win32.python.narkive.com › prrGHXIz › new-pywin32-errors-stating-object-has-no-attribute-and-the-code-worked-previously
[python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
Post by Kurt Munson xl2 = win32com.client.gencache.EnsureDispatch("Excel.Application") xl2.visible File "<stdin>", line 1, in <module> File "c:\python27\lib\site-packages\win32com\client\__init__.py", line 462, Post by Kurt Munson in __getattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
🌐
GitHub
github.com › mhammond › pywin32 › issues › 1694
AttributeError: module 'win32com.gen_py.00020905-0000-4B30-A977-D214852036FFx0x3x0' has no attribute 'CLSIDToClassMap' · Issue #1694 · mhammond/pywin32
April 27, 2021 - AttributeError: module 'win32com.gen_py.00020905-0000-4B30-A977-D214852036FFx0x3x0' has no attribute 'CLSIDToClassMap'#1694 ... i had try install pywin32 in a conda env, and use it by: from win32com import client word = client.Dispatch("Word.Application") and catch an error , like :
Author   mhammond
🌐
Python
mail.python.org › pipermail › python-win32 › 2006-April › 004590.html
[python-win32] broken install. win32com has no 'client'
April 26, 2006 - The biggest clue something is broken is I have no win32com.client object. import win32com win32com.client Traceback (most recent call last): File "<input>", line 1, in ? AttributeError: 'module' object has no attribute 'client' dir(win32com) ['SetupEnvironment', '__PackageSupportBuildPath__', ...
🌐
Reddit
reddit.com › r/learnpython › win32com.client issue.
r/learnpython on Reddit: win32com.client issue.
May 11, 2016 -

SOLVED! Solution Below (Thanks, u/tankorsmash)

I'm trying to do something pretty basic, just use the COM api for OneNote to export the structure in xml.

import win32com.client

onenote = win32com.client.Dispatch("Onenote.Application")
one = ""
onenote.GetHierarchy(None, onenote.HierarchyScope.hsPages, one)
print(one)

As per https://msdn.microsoft.com/en-us/library/office/jj680120.aspx, this should print in XML format. I think I'm fubaring the hsScope attribute though, because I get

Traceback (most recent call last):
  File "C:/Users/johnsnow/PycharmProjects/untitled/Testing/Tests.py", line 5, in <module>
    onenote.GetHierarchy(None, onenote.HierarchyScope.hsPages, one)
  File "C:\Users\johnsnow\AppData\Local\Programs\Python\Python35-32\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: Onenote.Application.HierarchyScope

Process finished with exit code 1

You may have noticed that onenote.HierarchyScope.hsPages isn't written exactly like it is in the API documentation. Well, naturally python expects it to be a variable so it throws an error. However, in the doc, there is no variable defined as just OneNote. (Unless I missed something. I don't know C#) I even tried using a string to "trick" it into sending the request exactly as it is written in the C# code:

import win32com.client

onenote = win32com.client.Dispatch("Onenote.Application")
one = ""
three = "OneNote"
onenote.GetHierarchy(None, three.HierarchyScope.hsPages, one)
print(one)

But I guess it passes the actual variable, because:

Traceback (most recent call last):
  File "C:/Users/johnsnow/PycharmProjects/untitled/Testing/Tests.py", line 6, in <module>
    onenote.GetHierarchy(None, three.HierarchyScope.hsPages, one)
AttributeError: 'str' object has no attribute 'HierarchyScope'

Process finished with exit code 1

The library and COM object seem fine, as this:

import win32com.client

onenote = win32com.client.Dispatch("Onenote.Application")
one = ""
#onenote.GetHierarchy(None, onenote.HierarchyScope.hsPages, one)
print(onenote)

Produces this:

<COMObject Onenote.Application>

Process finished with exit code 0

And I've just run out of ideas. This is my first time coding, and I'm afraid I've bit off more than I can chew. Once I get this one error sorted, I'm pretty confident I can finish the project, but win32com has so little documentation, I just can't figure it on my own.

==========Solution============

So it turns out, the first node attribute needs to be a null string. Passing null as advised in the documentation doesn't work. The output to variable apparently doesn't work, either. Also, scope attribute needs to be a numerical value. hsPages just doesn't translate. See Enumeration section of API Documentation. Working code:

import win32com.client

onenote = win32com.client.Dispatch("Onenote.Application")
start = ""
test = onenote.GetHierarchy(start, 4)

print(test)

Far simpler than I had ever hoped or realized. That being said, based on the documentation, I would never have found the solution.

Find elsewhere
🌐
Esri Community
community.esri.com › t5 › python-questions › win32-com-client › td-p › 73379
Solved: Win32.com client - Esri Community
May 31, 2017 - I got new pc and working on update my scripts. I am getting 'No module named win32com.client' on of them and I can quit remember how it is installed. I have 10.4.1 and python 2.7.10 that came with it. I believe i have download the correct one 'ad3‑2.0.2‑cp27‑cp27m‑win_amd64.whl' now i am trying to i...
🌐
Blogger
appshortcut.blogspot.com › 2013 › 04 › windowspythonattributeerror-module.html
Windows環境のPythonでAttributeError 「module' object has no attribute 'client'」 が発生
April 18, 2013 - >>> import win32com >>> xlApp = win32com.client.Dispatch("Excel.Application") Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'client' >>> import win32com.client · リンクを取得 · Facebook · Twitter ·
🌐
Narkive
tutor.python.narkive.com › 4HoH6W5A › cannot-import-win32com-client
[Tutor] cannot import win32com.client
When I installed "win32all-163.exe" I got 3 errors: 1) Registration of the AXScript Engine COM server failed. Installation will continue, but this server will require manual registration before it will function exceptions.AttributeError: 'module' object has no attribute '__import_pywin32_system_module__' 2) Registration of the Python Interpreter COM server failed.
🌐
Stack Overflow
stackoverflow.com › questions › 24003829 › win32com-client-error-with-python-3-4
Win32Com.Client error with Python 3.4 - Stack Overflow
June 16, 2014 - import win32com >>> win32com.client Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> win32com.client AttributeError: 'module' object has no attribute 'client' >>> import win32com.client Traceback (most recent call last): File "C:\Program Files (x86)\python\lib\site-packages\win32com\client\gencache.py", line 56, in __init__ _LoadDicts() File "C:\Program Files (x86)\python\lib\site-packages\win32com\client\gencache.py", line 106, in _LoadDicts f = open(os.path.join(win32com.__gen_path__, "dicts.dat"), "rb") FileNotFoundError: [Errno 2] No such file or directory: 'C:\\P
🌐
Alteryx Community
community.alteryx.com › t5 › Alteryx-Designer-Desktop-Discussions › Python-Error-CLSIDtopackagemap › td-p › 662319
Python Error - CLSIDtopackagemap - Alteryx Community
November 6, 2020 - I'm suddenly running into CLSIDtopackagemap when trying to run pywin32 related package (like xlwings or win32com.client). The issue appeared on both Alteryx and Anaconda3 IDE (spyder) I'm using. Previously pywin32 was functioning just fine. ... AttributeError: module 'win32com.gen_py.
🌐
Bytes
bytes.com › home › forum › topic › python
win32com.client.constants - AttributeError - Post.Byes
April 20, 2006 - On my machine, this runs fine, but when I try to run it on someone elses machine it blows up with an attribute error: <code> import win32com.client , pythoncom pythoncom.CoIni tializeEx(pytho ncom.COINIT_APA RTMENTTHREADED) myWord = win32com.client .dynamic.Dispat ch ("Word.Applicat ion") myWord.Visible = True myDoc = myWord.Document s.Open(FileName = "C:\Test.do c") myDoc .SaveAs(FileNam e = "c:\Test.ht m", FileFormat = win32com.client .constants.wdFo rmatHTML) myDoc.Saved=1 myWord.Quit () del myWord pythoncom.CoUni nitialize() </code> It's pretty simple code so I don't understand why it doesn't work. I verified that he has the same pywin32 module as me (build 207) and the same python version (2.4.2). Any ideas? ... Re: win32com.client .constants - AttributeError The constants are only available if you've run makepy on the Word object library.
🌐
Easy-online-courses
easy-online-courses.com › course › module-win32com-has-no-attribute-client-courses
Module Win32com Has No Attribute Client Courses
Posted: (2 days ago) Aug 17, 2021 · Fix for module win32com.gen_py has no attribute 'CLSIDToPackageMap'. Raw. win32com.client.py. # If errors are found, do this. # clear contents of C:\Users\<username>\AppData\Local\Temp\gen_py. # that should fix it, to test it type.
🌐
Stack Overflow
stackoverflow.com › questions › 65890196 › how-to-clear-the-attributeerror-for-win32com-of-object-has-no-attribute-getnam
python - How to clear the AttributeError for win32com of "object has no attribute 'GetNameSpace'" - Stack Overflow
I'm trying to download emails and pdf attachments for a certain time range but when trying to run it in Python, I'm receiving the error: "AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Application instance at 0x1796763072736>' object has no attribute 'GetNameSpace'" It used to work last week but not sure what went wrong with the code since I haven't touched it either. Sharing my entire code below. import win32com.client import os import time import datetime as dt import re DateFilter = dt.datetime.now() - dt.timedelta(days = 2) #Outlook MAPI outlook = win32com.client.
🌐
Reddit
reddit.com › r/learnpython › weird errorr trying to read outlook calendar
r/learnpython on Reddit: Weird errorr trying to read outlook calendar
June 18, 2020 -

I have written a program to read my outlook calendar (and write it to my google calendar), mostly just to practice some python/learn from it/for fun. Now this was all fun and games and it worked, although it needed some improvements.

However it stopped beging fun and games when it decided to break itself. Literally. I didn't chage a letter of code and suddenly it returns an errormessage.

The faulty bit of code seems to be:

import win32com.client

def read_outlook_calendar(some arguments):
    Outlook = win32com.client.Dispatch("Outlook.Application")
    more of this function

where this worked before, it now returns the following error:

  File "syncal2.py", line 17, in <module>
    appointments = fun.read_outlook_calendar(begin = begin, end = end)
  File "C:\Users\Gebruiker\Documents\Agendaproject\tidy\fun.py", line 8, in read_outlook_calendar
    Outlook =  win32com.client.gencache.EnsureDispatch("Outlook.Application")
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch
    return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\__init__.py", line 37, in __WrapDispatch
    klass = gencache.GetClassForCLSID(resultCLSID)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\gencache.py", line 183, in GetClassForCLSID
    mod = GetModuleForCLSID(clsid)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\gencache.py", line 226, in GetModuleForCLSID
    mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\gencache.py", line 266, in GetModuleForTypelib
    AddModuleToCache(typelibCLSID, lcid, major, minor)
  File "C:\Users\Gebruiker\anaconda3\lib\site-packages\win32com\client\gencache.py", line 552, in AddModuleToCache
    dict = mod.CLSIDToClassMap
AttributeError: module 'win32com.gen_py.00062FFF-0000-0000-C000-000000000046x0x9x6' has no attribute 'CLSIDToClassMap'

So yeah, how do I unfuck this?

🌐
Python
mail.python.org › pipermail › python-win32 › 2007-August › 006147.html
[python-win32] python com error - 'module' object has no attribute 'CLSIDToClassMap' strangeness
August 1, 2007 - Importing module Failed to execute ... info.major, info.minor) File "C:\Python25\Lib\site-packages\win32com\client\gencache.py", line 554, in AddModuleToCache dict = mod.CLSIDToClassMap AttributeError: 'module' object has no attribute 'CLSIDToClassMap' Deleting the gen_py ...
Top answer
1 of 7
66

I had the same issue and I resolved it by following the instructions here: https://mail.python.org/pipermail/python-win32/2007-August/006147.html

Deleting the gen_py output directory and re-running makepy SUCCEEDS and subsequently the test application runs OK again.

So the symptom is resolved, but any clues as to how this could have happened. This is a VERY long running application (think 24x7 for years) and I'm concerned that whatever caused this might occur again.

To find the output directory, run this in your python console / python session:

import win32com
print(win32com.__gen_path__)

or, even better, a one-liner in the command line:

python -c "import win32com; print(win32com.__gen_path__)"

Based on the exception message in your post, the directory you need to remove will be titled '00020813-0000-0000-C000-000000000046x0x1x9'. So delete this directory and re-run the code. And if you're nervous about deleting it (like I was) just cut the directory and paste it somewhere else.

💡Note that this directory is usually in your "TEMP" directory (copy-paste %TEMP%/gen_py in Windows File Explorer and you will arrive there directly).

I have no idea why this happens nor do I know how to prevent it from happening again, but the directions in the link I provided seemed to work for me.

2 of 7
22

A more straightforward solution was posted in a related question Issue in using win32com to access Excel file.

Basically, you just need to delete the folder C:\Users\<your username>\AppData\Local\Temp\gen_py and rerun your code.

💡TIP: You can also put in your Windows file explorer %TEMP%\gen_py to access it directly, and then delete its content.