Question

I have a Tkinter program that i use for time management. I decided to have it scan my inbox in outlook to check emails for tags, and then based on the tag, add it to my list of tasks to do for the night.

The code i wrote works just fine, but i'm getting an error when I import win32com.client. I can import it in IDLE, but it is having problems importing when i try to run the code with a .bat file, or double clicking the .py file.

I have found several people with similar problems, but from what i can tell, it's having problems with win32api module, or pywin32

Traceback (most recent call last):
    File "my_program_filename.py", line 1, in <module>
import win32com.client
    File "c:/Python27/lib/site-packages/win32com/__init__.py", line 5, in <module>
import win32api, sys, os
ImportError:  DLL load failed: The specified module could not be found

I'm really confused. When i get the sys.path it's the same with IDLE as it is running from the .py file with the exception of an added "c:/users/username/desktop/timer" for my .py file.

I'm really lost and haven't had to mess with the system path, but I'm not able to figure out what i need to do to fix this.

What do I need to do to get pywin32 working so I can use win32com.client?

Any help is greatly appreciated. Thanks!

Was it helpful?

Solution 2

this is an issue of not having the correct paths in the sys.path. If you make sure that all of the pywin32 folders are in the sys.path(If you check in IDLE it can show that the folders are included even when they aren't?!?!?).

You also have to make sure you run your code from inside your Python directory or it will fail to import win32api. I also found that if you do anything in a function that uses pywin32 and you accidentally misspell the function when you call it, the whole import fails without telling you your function is misspelled. You can also navigate to the /Python27/Lib/site-packages/win32com/client folder and run makepy.py to make sure the right Object library is installed.

When you run makepy.py, you select the COM object you want to use and it creates packages specific to what you want to use. I don't fully understand why this is, but once i did this and ran my file from the Python folder it worked! There is a more in depth explanation on how to get this working right here.

OTHER TIPS

IIRC, the problem was attempting to link to the debug build. I think i had to dupe the release build and rename it to be debug or something.

try building release and see if it "just works". if so, you have a direction to explore

I found this link to be the solution rather than the win32com/client as indicated above: win32com import error python 3.4

in my case typing in cmd: python C:\Python27\Scripts\pywin32_postinstall.py -install

results in command line

I hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top