By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

How to import win32com.client though it's installed?

P: 6
Hello,

I'm trying to use the in32com.client for writing into Excel with Dispatch() (on a windows machine using python 2.7.1). I downloaded pywin from http://sourceforge.net/projects/pywin32/ into the C:\Python27 folder and hit both setup.py and pywin32_postinstall.py

I'm running my python program in the windows command prompter cmd. But it won't run because it cannot import the win32com.client.
When prompting or running my program containing the import:
python import win32.client

I keep getting the following error message:
python: can't open file ... [Errno 2] no such file or directory

I've been trying in different combinations of 'import' 'python import', file name, complete file loaction, but nothing works. I merely keep getting error messages alternating from English to German (which is the language setting for the computer)

Any idea what the problem could be? Should I try a different pywin version? Or save it differentlx? Am I not doing the installation properly?

Thanks for any help.

Amelie
excel = win32com.client.Dispatch('Excel.Application')
Dec 22 '10 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 621
Try explicitly setting the path to the .exe's directory.
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. sys.path.append("path/to/exe")
  3. import win32.client
  4. # and/or
  5. import win32com.client 
If that doesn't help then you have not installed it correctly, so install it again this time with setup.py only (which may be a good idea anyway).
Dec 22 '10 #2

P: 6
I've gotten a bit further, but still couldn't get it to work. I'm pretty new to programming, so I don't quite know where to go I've I have a suspicion
I added the path as you suggested and I also reinstalled the zip folder, unzipped, ran setup.py (only). I installed it where the default setting put it.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2. sys.path.append("C:\\Python27\\pywin32-214\\pywin32-214\\com")
  3. import win32com
I am now getting a new error message:

Z:\testpython>python version1.py
Traceback most recent call last>:
File "version1.py", line 5, in <module>
import win32.com
File "C:\Python27\pywin32-214\pywin32-214\com\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: No module named win32api

Is that caused by the location of the __init__.py being unexpected? Should I move the content or the win3232-214 folder into the parent folder, Python27? Or should I modify the path in the __init__.py file (that seems a bit fishy...)?

Thanks again,

Amelie
Dec 23 '10 #3

P: 6
Help!
I am still stuck on this (I thought I could use xlrd/xlwt instead, but now have to return to Dispatch).

I went through the Installation Problems on http://www.python.net/crew/mhammond/...nProblems.html. As described in the first paragraph, I do have 2 versions (and am no administrator). I deleted the version in C:\Python27 but whenever I startup IDLE it re-creates it.

It seems like no one else is having this problem (most people just seem forget to install it), so if you have ANY idea, please let me know. I really really need help on this.
Jan 31 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.