简体   繁体   中英

Error installing and running pywin32 2.7

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

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 .

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.

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

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.

I encountered the same problem as the author. I used the script from Tim Golden python staff to print a text file. After running, there are errors like the following:

pywintypes.error: (31, 'ShellExecute', 'A device attached to the system is not functioning.')

My system is windows 7, 64 bit. The python is python2.7 64bit.

I think the error has nothing to do with pywin32's installation or windows system settings. I guess the reason is the default opening software setting to .txt file. Because after I changed the default opening software from Nodepad++ to notepad, then I can print the file on my Hp printer.

在Windows 10上PowerShell command as admin运行,作为Command line prompt (as admin)失败。

Steps to install pywin32 -

  1. net user Admin /add
  2. net user Admin
  3. net localgroup Administrators Admin /add
  4. runas /user:Admin pywin32-217.win32-py2.7.exe

I faced same issue when I installed pywin32-219.win-amd64-py2.7.exe by running the installer file as administrator.

Once I installed it by simply executing the file (double clicking on it), I didn't face this issue again.

I am on Windows 7 64 bit SP1 with Python 2.7.9 (64 bit)

However, I did notice one strange thing, if I just double clicked the installer exe it took slightly over 20 seconds for the prompt to appear whether I would like to run the exe file or not, whereas in case of running the file as administrator, it happened right then (didn't have to wait for that long) I am using 120 GB SSD so can't question the slowness of Hard disk in this case.

Anyways, here's the output after successful installation of pywin32 in my case:

Copied pythoncom27.dll to C:\Windows\system32\pythoncom27.dll
Copied pythoncomloader27.dll to C:\Windows\system32\pythoncomloader27.dll
Copied pywintypes27.dll to C:\Windows\system32\pywintypes27.dll
Registered: Python.Interpreter 
Registered: Python.Dictionary 
Registered: Python 
-> Software\Python\PythonCore\2.7\Help[None]=None
-> Software\Python\PythonCore\2.7\Help\Pythonwin Reference[None]='C:\\Python27\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory C:\Python27\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.

我用这个解决了它:

pip install pypiwin32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM