Reputation: 888
I'm trying to install the pyWin32
on windows 7, 64 bit and python version 3.5.2. I can't find the pyWin32
. I download and install the pyWin32
files from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook and getting error as below:
Exception:
Traceback (most recent call last):
File "C:\Users\nisarahmed.h\AppData\Local\Programs\Python\Python35-32\Lib\shutil.py",
line 381, in _rmtree_unsafe os.unlink(fullname)
FileNotFoundError: [WinError 2] The system cannot find the file specified:
'C:\\Users\\NISARA~1.H\\AppData\\Local\\Temp\\pip-ditl64b5-unpack\\pypiwin32-219-cp35-none-win32.whl'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\basecommand.py", line 215, in main status = self.run(options, args)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\commands\install.py", line 335, in run wb.build(autobuilding=True)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\wheel.py", line 749, in build self.requirement_set.prepare_files(self.finder)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies))
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file session=self.session, hashes=hashes)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\download.py", line 821, in unpack_url hashes=hashes
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\download.py", line 671, in unpack_http_url rmtree(temp_dir)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
raise attempt.get()
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\_vendor\retrying.py", line 247, in get six.reraise(self.value[0], self.value[1], self.value[2])
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\_vendor\six.py", line 686, in reraise raise value
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\_vendor\retrying.py", line 200, in call attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\utils\__init__.py", line 102, in rmtree onerror=rmtree_errorhandler)
File "C:\Users\nisarahmed.h\AppData\Local\Programs\Python\Python35-32\Lib\shutil.py", line 488, in rmtree return _rmtree_unsafe(path, onerror)
File "C:\Users\nisarahmed.h\AppData\Local\Programs\Python\Python35-32\Lib\shutil.py", line 383, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "c:\users\nisarahmed.h\appdata\local\programs\python\python35-32\lib\site-packages\pip\utils\__init__.py", line 110, in rmtree_errorhandler
if os.stat(path).st_mode & stat.S_IREAD:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\NISARA~1.H\\AppData\\Local\\Temp\\pip-ditl64b5-unpack\\pypiwin32-219-cp35-none-win32.whl'
Thanks in advance
Upvotes: 1
Views: 625
Reputation: 888
I found the answer from Stackoverflow. pip install pywin32
didn't work for me but pip install pypiwin32
did.
Upvotes: 0
Reputation: 1087
I had the same issue. I circumvented the problem by calling the required functions directly, for example:
from ctypes import *
FILE_LIST_DIRECTORY = 0x1
FILE_SHARE_DELETE = 0x00000004
FILE_SHARE_READ = 0x00000001
FILE_SHARE_WRITE = 0x00000002
FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
OPEN_EXISTING = 0x3
handle = windll.kernel32.CreateFileW(
path,
FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
None,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
None
)
instead of:
import win32file
import win32con
hDir = win32file.CreateFile (
path_to_watch,
FILE_LIST_DIRECTORY,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS,
None
)
I wanted to watch changes in a directory. Tim Golden has examples to use the PyWin32 API for this exact purpose, but I failed to install the package.
Since I only needed two functions I ended up referencing them directly from ctypes.windll.kernel32
. This might not be feasible for more complex projects. The Windows Developer Center documents the required functions quite well, so it's easy to find out required flags.
Note that you might have to differentiate unicode and ansi names, e.g. CreateFileW (Unicode) and CreateFileA (ANSI), when looking for the function. This caused some confusion for me, as I was searching for CreateFile
rather than CreateFileW
.
Upvotes: 1