57

When running python26 under windows OS (64bits)..... I have got errors like:

import win32api" error in Python 2.6: pywintypes26.dll

or

pythoncom26.dll missing
ImportError: DLL load failed: The specified module could not be found.

I have done the msi installation for python26 all dlls can be found under C:\Python26\Lib\site-packages\pywin32_system32

agf
  • 148,965
  • 36
  • 267
  • 227
Vin.X
  • 4,595
  • 3
  • 26
  • 35
  • 5
    After I move/copy pywintypes26.dll and pythoncom26.dll to c:\Python26\Lib\site-packages\win32 -> Solve the problem! – Vin.X Aug 30 '11 at 03:37
  • 1
    Just had this problem on Python 2.7.14, running pip uninstall pywin32 followed by pip install pywin32 made it work, though I got a warning that pip uninstall of a 'distutils' project is deprecated. – Mark Allen Apr 05 '18 at 17:46
  • This sounds like a Python installation issue; the best solution should be to reinstall Python (if possible). I've only had this problem occur on one machine and was immediately fixed after reinstalling Python – Jon Sep 25 '19 at 19:11
  • Just had this problem on Python 2.7.12 and running `pip uninstall pywin32` followed by `pip install pywin32` did not work for me. Dave Bremer's answer below did work. – Ross Bencina Dec 05 '19 at 14:33

11 Answers11

78

After I copy pywintypes26.dll and pythoncom26.dll from C:\Python26\Lib\site-packages\pywin32_system32 to C:\Python26\Lib\site-packages\win32 -> Solve the problem!

Sid
  • 2,047
  • 1
  • 7
  • 24
Vin.X
  • 4,595
  • 3
  • 26
  • 35
39

I also hit a problem importing win32api.

The post-install script for pywin32 failed, which should copy pythoncom26.dll, pythoncomloader26.dll, and pywintypes26.dll, among other things. I ran it by hand and my installation was fixed.

python scripts\pywin32_postinstall.py -install
Nagendra Rao
  • 6,406
  • 5
  • 47
  • 87
Dave Bremer
  • 391
  • 3
  • 2
  • 4
    This may require Administrator priviliges on Win7 (64 bit) or fail with `You do not have the permissions to install COM objects.` yet report `The pywin32 extensions were successfully installed.`. – handle Apr 08 '14 at 08:15
  • 1
    This solves my problem partially. If I run with python in my current directory: `python C:\mypath\myscript.py` the post install script appears to have done it's job and is working as intended. If on the other hand I run with my target script in my currently directory: `C:\mypath\python myscript.py` the post script did not work and I had to do as the accepted answer suggested and move the DLLs into the win32 site-packages directory by hand. – OxCantEven Jun 11 '15 at 13:33
12

I had a similar problem when installing under 64 bit Python 3.4.2. I ran the install executable pywin32‑219.win‑amd64‑py3.4.exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/ .

On the site it states clearly:

"Python 3.4 users must manually run python.exe Scripts\pywin32_postinstall.py -install from an elevated command prompt."

which I did not do first time round; I installed from a normal prompt getting the following feedback:

c:\python34>python.exe Scripts\pywin32_postinstall.py -install
Copied pythoncom34.dll to C:\Python34\pythoncom34.dll
Copied pywintypes34.dll to C:\Python34\pywintypes34.dll
You do not have the permissions to install COM objects.
The sample COM objects were not registered.
etc.etc.
Finishing with "The pywin32 extensions were succesfully installed" ... 

I only read the last sentence and I started to run some code resulting in getting these dll load fails.

So, did some research, and started an elevated prompt (how: see "http://www.sevenforums.com/tutorials/783-elevated-command-prompt.html") and again ran:

c:\python34>python.exe Scripts\pywin32_postinstall.py -install
Copied pythoncom34.dll to C:\Windows\system32\pythoncom34.dll
Copied pywintypes34.dll to C:\Windows\system32\pywintypes34.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\3.4\Help[None]=None
-> Software\Python\PythonCore\3.4\Help\Pythonwin Reference[None]='C:\\Python34\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.

And now my code runs happily (as far as this matter is concerned... sigh, so much other stuff to do).

MZA
  • 806
  • 9
  • 14
7

Run the installer as Administrator and it works:

  • Right click on pywin32-installer.exe
  • Choose "Run as Administrator"
Lucidity
  • 1,059
  • 14
  • 17
  • This should be everyone's first attempt (because it's easiest). If you already ran the installer, just run it again as admin and boom fixed. Works with python35. – Radical Edward May 18 '16 at 21:54
7

As suggested above the post install script is not run, this issue can be seen when installing from a wheel (As I encountered)

python scripts\pywin32_postinstall.py -install

If find you have this issue when installing via wheels, then installing it from here can solve the above issue.

https://pypi.python.org/pypi/pypiwin32

JamesD
  • 2,176
  • 19
  • 35
2

There appears to be a bug in the installer. The recommended workaround in the ticket is the same one as proposed by Dave Bremer.

Jason R. Coombs
  • 36,798
  • 8
  • 75
  • 83
2

I could fix this situation by removing all installed Python3.4 versions (had forgotten to uninstall 3.4.1 before installing 3.4.2), deleting C:\Python34 and after installing Python 3.4.2 pywin32-219.win32-py34.exe could be installed and called without problems. So, copying around DLLs should NOT be necessary!

MKesper
  • 394
  • 4
  • 15
1

If the above didn't fix the problem, you're still missing the msvcr100.dll file. It's either in your \System32\ folder, or more likely in your c:\PythonXX\Lib\site-packages\win32\ folder.

That fixed it for me after hours of search to no avail, even though it looks like the import still isn't resolved as it should be (PyCharm still gives me the squiggly underline), but it works.

aljabear
  • 5,832
  • 5
  • 40
  • 69
Sol
  • 11
  • 2
1

I don't whether it's too late or not to answer this question. I also hit this problem, and I tried every method above, but neither of them worked.
Finally, I found the reason. When we install pywin32, we must choose the one that fits python's version(2.6, 2.7, 3.3, etc) and python's bit number(x64 or x86). Notice, it must fits python's bit number, not PC's bit number. If you install x86 python in a x64 PC, you have to install a pywin32 with x86.

styshoo
  • 403
  • 4
  • 9
1

First I was using pip to install pywin32 in anaconda environment, that's why no matter what I did it was failing. After trial and error, I figured out that conda install pywin32 is the right way to install pywin32 in the anaconda package manager.

Harsh Nagarkar
  • 606
  • 5
  • 14
1

I always install the Active State Python distro which installs the win32 packages for you and gets it right.

David Heffernan
  • 572,264
  • 40
  • 974
  • 1,389