Error installing and running pywin32 2.7

26,824

Solution 1

I had the same problem, but solved it a bit differently. Instead of creating another admin account, I was able to execute the pywin32-217.win32-py2.7.exe successfully from a command prompt that I started with Run as Administrator.

Solution 2

An alternate solution is what Mark Hammond suggests on the pywin32 mailing list:

This seems to happen if User Access Control (UAC) is disabled - is it disabled for you?

Either way, try running "python scripts\pywin32_postinstall.py -install" from the root of the install directory and things should finish registering - that should fix the next error you see.

This worked fine for me.

Solution 3

You must not install as administrator, see this bug report:

This is maybe because you are running Windows under the "Administrator" account and anything you normally run is equal to a "run as Administrator"

And paradoxically running the installation of pywin32 on Windows 7 as Administrator causes this error.

So a workaround is to create another admin account

net user Admin /add
net user Admin
net localgroup Administrators Admin /add

and then run the pywin32 installation with

runas /user:Admin pywin32-217.win32-py2.7.exe

Solution 4

None of the solutions helped me (Sitting on Windows 10).

But I finally got it fixed when I ran c:\python27\scripts\pywin32_postinstall.py -install

After installation you can try to run the installer again just to be sure, worked for me.

Solution 5

Running from a PowerShell command as admin worked for me on Windows 10, where as a Command line prompt (as admin) failed.

Share:
26,824

Related videos on Youtube

Mike
Author by

Mike

Updated on July 09, 2022

Comments

  • Mike
    Mike almost 2 years

    I am coming up with a couple errors after installing:

    pywin32-217.win32-py2.7

    I have recently upgraded ArcGIS to 10.1 and it uses Python 2.7 (as opposed to 2.6 that came with ArcGIS 10.0)

    When I run the installer on a Windows 7 64 bit, it installs, but throws the following message:

    close failed in file object destructor:

    sys.excepthook is missing

    lost sys.stderr

    I had a simple python script to print to a printer from a folder containing .pdf files which worked before my upgrade

    import arcpy, glob, win32api, os
    
    pdfLoc = arcpy.GetParameterAsText(0)
    
    try:
        copies = int(arcpy.GetParameter(1))
    except:
        copies = 1
    
    for pdfname in glob.glob(os.path.join(pdfLoc, "*.pdf")):
        fullpath = os.path.join(pdfLoc, pdfname)
        for copy in range(copies):
            win32api.ShellExecute(0, "print", pdfname, None, ".", 0)
    
    del fullpath
    del pdfname
    del pdfLoc
    

    Now when I run the script, I get the following error:

    Traceback (most recent call last): File "Z:\ESRI\Python\Solstice_Tools_Scripts\Printer_Tools\Batch_Print_From_PDF_Only\BatchprintFromPDFOnly_Test.py", line 34, in win32api.ShellExecute(0, "print", pdfname, None, ".", 0) error: (31, 'ShellExecute', 'A device attached to the system is not functioning.')

    Failed to execute (BatchPrintFromPDFOnly2).

    I've been googling around and have tried a few solutions, like running the executable in troubleshooting mode, but the error persists. Can anyone suggest what may cause this?

    As a side note, I upgraded 4 computers in my company to the new version of python and ArcGIS, and only one of them is throwing this error. The rest work fine.

    Thanks, Mike

    • Thomas K
      Thomas K almost 12 years
      If it's only a problem on one computer, is it simple to uninstall/reinstall on that machine?
    • Mike
      Mike almost 12 years
      @ Thomas. I've tried to uninstall multiple times. Unfortunately, the issue still persists.
  • mike
    mike over 10 years
    worked for me too, just have to setup a password for the account (can be done from computer management).
  • Roney Michael
    Roney Michael over 10 years
    This worked and it seems to be a much easier solution. Kudos!
  • Flak DiNenno
    Flak DiNenno about 10 years
    Same worked for me. I also made sure that my path variables PYTHONPATH=D:\Python27 and PYTHONPATH=D:\Python27\Scripts were set properly.
  • Sun Wukong
    Sun Wukong almost 10 years
    Run this post-install script worked for me, as the "Run as Administrator" tip had failed. Thx
  • Marcel Wilson
    Marcel Wilson over 9 years
    Run as Admin worked for me as well. I'd be curious to understand why.
  • Chiwda
    Chiwda over 9 years
    Yup! This worked perfectly - just don't forget to set the password or you may get the error: "1327: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced." Haha, guess how I know this... :-)
  • Chiwda
    Chiwda over 9 years
    Oh, and this may seem obvious, but remember your pywin file may not be the same so the last line may differ. For example, mine was: runas /user:Admin pywin32-219.win-amd64-py2.7.exe
  • Atiq Rahman
    Atiq Rahman about 9 years
    Running the exe as admin didn't work for me. But as he said starting a command prompt as admin and then running the pywin32 from there worked!! Strange! Mine is Windows 8.1, python 2.7.9 64 bit
  • evt
    evt over 8 years
    This also worked for me, whereas directly running the exe in admin did not (same as atique).
  • maxisam
    maxisam about 8 years
    That is AMAZING. I actually didn't login as Administrator but still got this error. However, once I use runas with my current account, it works.
  • Kay Zed
    Kay Zed almost 8 years
    Same problem as asker and this solves it for pywin32-220.win32-py2.7
  • Aminah Nuraini
    Aminah Nuraini almost 8 years
    I got ImportError: DLL load failed: The specified module could not be found because of that
  • Aminah Nuraini
    Aminah Nuraini almost 8 years
    I am using Windows 10 too btw. I didn't get this problem in the previous versions of Windows
  • hydroman
    hydroman almost 6 years
    ran c:\python27\scripts\pywin32_postinstall.py -install what do you mean by this?
  • Conrad Selig
    Conrad Selig almost 5 years
    Same thing here, if default app is notepad instead of notepad++ Tim's script works just fine.