import win32api error in Python 2.6
Asked Answered
E

12

56

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

Electropositive answered 30/8, 2011 at 3:35 Comment(4)
After I move/copy pywintypes26.dll and pythoncom26.dll to c:\Python26\Lib\site-packages\win32 -> Solve the problem!Electropositive
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.Coben
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 PythonJamila
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.Petropavlovsk
E
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!

Electropositive answered 2/9, 2011 at 4:56 Comment(7)
I would really like to know why the dlls are reported as missing, but this solution worked for my problem too. (For the record, I had another version of python installed also, maybe there is a bug in the installer somehow?)Hague
I had the same problem nearly a year later. Thanks for the answer.Goulden
This problem (and this solution) continues into the 217 and 218.4 installers for Python2.7. Disappointing, reallyKirkwood
The same thing continues into 218.5 installers for python 3.4.Wiggly
I wish you would mention in your answer WHERE pywintypes26.dll comes from as well (I see it's in the original post)Knelt
They can be found if you open the installer as a zip file and browse to \PLATLIB\pywin32_system32\.Salacious
Still seeing problem with 3.6 and 220 installer. Also, the dll copy trick doesn't seem to work.Allsopp
M
38

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
Mossback answered 4/2, 2014 at 21:37 Comment(2)
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..Canny
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.Agricola
S
11

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).

Slobbery answered 28/11, 2014 at 22:20 Comment(0)
T
7

Run the installer as Administrator and it works:

  • Right click on pywin32-installer.exe
  • Choose "Run as Administrator"
Transcribe answered 20/3, 2015 at 13:25 Comment(1)
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.Incorporable
I
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

Institutor answered 8/2, 2016 at 14:58 Comment(1)
This fixed it for me. I was using python 2.7.9 x86 python.Embitter
T
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.

Tesstessa answered 27/8, 2014 at 13:16 Comment(0)
Z
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!

Zetta answered 26/11, 2014 at 8:4 Comment(1)
Agreed; you should only need to reinstall PythonJamila
P
1

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

Patrol answered 30/8, 2011 at 6:28 Comment(0)
M
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.

Miriam answered 23/2, 2017 at 19:14 Comment(0)
S
1

I don't know 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 fit 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.

Space answered 14/9, 2017 at 5:39 Comment(0)
S
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.

Selfish answered 24/9, 2019 at 4:27 Comment(0)
C
0

In my case i had to copy pywintypes26.dll and pythoncom26.dll files into C:\Windows\System32 folder to work it properly in jupyter notebook.

I am using windows 10 OS with multiple python versions

Christiechristin answered 16/11, 2021 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.