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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amelie Lesser
    New Member
    • Dec 2010
    • 6

    #1

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

    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_postins tall.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('Exce l.Application')
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Try explicitly setting the path to the .exe's directory.
    Code:
    import sys
    sys.path.append("path/to/exe")
    import win32.client
    # and/or
    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).

    Comment

    • Amelie Lesser
      New Member
      • Dec 2010
      • 6

      #3
      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.

      Code:
      import sys
      sys.path.append("C:\\Python27\\pywin32-214\\pywin32-214\\com")
      import win32com
      I am now getting a new error message:

      Z:\testpython>p ython version1.py
      Traceback most recent call last>:
      File "version1.p y", line 5, in <module>
      import win32.com
      File "C:\Python27\py win32-214\pywin32-214\com\win32co m\__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

      Comment

      • Amelie Lesser
        New Member
        • Dec 2010
        • 6

        #4
        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.

        Comment

        Working...