49

I am trying to install pywin32. I downloaded it from sourceforge.net. When I run

setup.py install

it shows "Unable to find vcvarsall.bat". I Googled about it and found that I have to install MinGW and set path then run

python setup.py build --compiler=mingw32

but it's showing

Can't find a version in Windows.h

Can anybody help? (I have a trial version of Visual Studio 2010 Ultimate installed and MinGW C and C++ compiler installed. Operating system: Windows 7.)

Can anybody tell me a source from where I can download Python binaries already compiled in MinGW, so I don't have to do all this. Or if I can get a python which already have Windows modules.

Mark Amery
  • 110,735
  • 57
  • 354
  • 402
narayanpatra
  • 5,427
  • 13
  • 45
  • 59

5 Answers5

131

You can install pywin32 wheel packages from PYPI with PIP by pointing to this package: https://pypi.python.org/pypi/pypiwin32 No need to worry about first downloading the package, just use pip:

pip install pypiwin32

Currently I think this is "the easiest" way to get in working :) Hope this helps.

Kanguros
  • 1,847
  • 2
  • 11
  • 17
  • 4
    It's nice that it could be installed just like that. But try writing a Windows service and running it using virtual env - no good until you make DLLs from `pypiwin32_system32` visible for the system. Running `pywin32_postinstall.py` won't work either, as it looks for DLLs in `pywin32_system32` (without *pi* in the middle). Going with @jpmc26's answer works better in that case. Here's a link to a not so popular question, but a very useful one, about that issue: http://stackoverflow.com/a/34942168/279806 – kishkin Jun 30 '16 at 19:16
  • pip is easiest way to install python libraries.(on any platform) – BladeMight Oct 11 '16 at 19:07
  • 1
    Doesn't seem to work on python 3.6 (worked on 3.5) – Rehan Jul 05 '17 at 17:34
  • 3
    I think the correct command on windows should be: `python -m pip install pypiwin32` (pip is not necessarily in the path) – Peter Lamberg Jul 11 '17 at 15:43
  • @PeterLamberg I tried that and it looked like it worked, but both `import pywin32` and `import pypiwin32` give "no module named ..." errors in Python 3.5. – Mark Ransom Jul 15 '17 at 05:24
  • Sometimes you want to install packages on a machine that does not have internet access or on a whole bunch of machines and are on a slow or capped connections .. in those cases this comes in handy: `pip download pypiwin32` downloads to current dir `pip install --no-index --find-links=. pypiwin32` installs from current dir - easy and portable if put on a script and run from USB or network drive – NiKiZe Aug 05 '17 at 21:15
  • @MarkRansom I checked and it works at least on that win10 machine. Possibly something to do with how the script is run? – Peter Lamberg Aug 13 '17 at 14:19
  • `python -m pip install pypiwin32` works under Windows 10 with python 3.6. You need to run in Power Shell as Administrator. – Mike Nov 24 '17 at 05:33
  • Worked for me (Win 10, Python 3.7, both 64 bit) like a charm! Make sure to remove `pywin32` using the deinstaller and/or `pip uninstall` if you previously installed it. – MemAllox Oct 09 '18 at 05:45
  • @MarkRansom Try `import win32api as w32a` and `import win32con as w32c` – GLRoman Jun 17 '19 at 19:13
  • 1
    Per https://github.com/mhammond/pywin32/issues/1151#issuecomment-360563280, I think you should now be using `pywin32`, not `pypiwin32`, and that this has been the case since at least early 2018. Are you able to test and then update this answer accordingly? – Mark Amery Jul 03 '19 at 09:47
36

are you just trying to install it, or are you looking to build from source?

If you just need to install, the easiest way is to use the MSI installers provided here:

http://sourceforge.net/projects/pywin32/files/pywin32/ (for updated versions)

make sure you get the correct version (matches Python version, 32bit/64bit, etc)

Nzbuu
  • 5,076
  • 27
  • 48
Corey Goldberg
  • 53,391
  • 24
  • 118
  • 137
14

I disagree with the accepted answer being "the easiest", particularly if you want to use virtualenv.

You can use the Unofficial Windows Binaries instead. Download the appropriate wheel from there, and install it with pip:

pip install pywin32-219-cp27-none-win32.whl

(Make sure you pick the one for the right version and bitness of Python).

You might be able to get the URL and install it via pip without downloading it first, but they're made it a bit harder to just grab the URL. Probably better to download it and host it somewhere yourself.

Community
  • 1
  • 1
jpmc26
  • 23,237
  • 9
  • 76
  • 129
  • upvoted. note however, the original answer is 5 years old, before .whl format was in use :) – Corey Goldberg Jan 30 '16 at 14:04
  • @CoreyGoldberg True, but even before wheel, you could actually do something similar with the binary eggs: `easy_install pywin32-216.win32-py2.7.exe`. The advantages being that you can script this and that it supports virtualenv. Maybe not 5 years ago, but for several years (at least 3 or 4). – jpmc26 Jan 30 '16 at 18:33
  • fair enough... But I'm curious why you point to the "unofficial windiows binaries"? AFAICT, you can pip install from the .whl files host in my original answer. However they haven't been updated for build 220 (whereas the binaries on the unofficial build site has been updated). I was going to update my answer for modern pip tooling, but want to point to a freshly updated build. (FWIW I haven't used Windows since before this answer was even posted :) – Corey Goldberg Jan 31 '16 at 04:19
  • @CoreyGoldberg ? I don't see any wheels on SourceForge where you linked. Only the binary egg executables. The unofficial site provides wheels for a plethora of Python libraries. My experience has generally be *very* good with them. They do a very good job of packaging everything you need to get something up and running, even when official packages tell you to install something separately. So they tend to be my go-to for Windows binaries for Python. They may lag behind a little, but they'll catch up fairly soon. – jpmc26 Jan 31 '16 at 05:28
  • sorry, the link I was referring to is actually in @Kanguros's answer: https://pypi.python.org/pypi/pypiwin32 – Corey Goldberg Jan 31 '16 at 05:34
  • @CoreyGoldberg That appears also to be some sort of unofficial build. Note the "pi" in "pypiwin32". It probably didn't just come up in my searching because of that. If it *is* maintained by the original group, they do a fairly poor job of communicating it. Most likely, it's just someone running `wheel convert` against the egg. But yeah, that works, too (a bit better even if there's no external dependencies). – jpmc26 Jan 31 '16 at 05:58
  • 2
    you are right. official builds are not published on PyPI at all. The package name is just registed on PyPI, and links to a sourceforge url where .exe updates are actually published: http://sourceforge.net/projects/pywin32/files/ If this is actually a project that is in high use, it should *really* move to modern dev hosting, with a modern DVCS, issue tracking, and a sane release mecahnism that uploads to PyPI. If I had any interest, I would offer to help, but I really don't. perhaps someone should nudge the maintainer (Mark Hammond) to see what his plans are and if he needs a hand. – Corey Goldberg Jan 31 '16 at 20:24
4

I had the exact same problem. The problem was that Anaconda had not registered Python in the windows registry.

1) pip install pywin
2) execute this script to register Python in the windows registry
3) download the appropriate package form Corey Goldberg's answer and python will be detected

Vorac
  • 7,533
  • 7
  • 51
  • 87
3

Quoting the README at https://github.com/mhammond/pywin32:

By far the easiest way to use pywin32 is to grab binaries from the most recent release

Just download the installer for your version of Python from https://github.com/mhammond/pywin32/releases and run it, and you're done.

Mark Amery
  • 110,735
  • 57
  • 354
  • 402