Can't run pywin32 post install - python

I'm trying to use winpexpect on windows 7 64 bit on an AMD processor. For this, I installed pywin32, the executable called pywin32-214.win-amd64-py2.7. The graphical installer seemed to run successfully, but I get this error when I try to import winpexpect:
>>> import winpexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alexei\wordseer_flask\venv\lib\site-packages\winpexpect.py", li
ne 11, in <module>
import pywintypes
File "C:\Users\Alexei\wordseer_flask\venv\lib\site-packages\pywin32-214-py2.7-
win32.egg\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\Alexei\wordseer_flask\venv\lib\site-packages\pywin32-214-py2.7-
win32.egg\pywintypes.py", line 64, in __import_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: %1 is not a valid Win32 application.
When I try to run C:\Python27\Scripts\pywin32_postinstall:
C:\Windows\system32>C:\Python27\Scripts\pywin32_postinstall.py -install
Traceback (most recent call last):
File "C:\Python27\Scripts\pywin32_postinstall.py", line 601, in <module>
install()
File "C:\Python27\Scripts\pywin32_postinstall.py", line 311, in install
LoadSystemModule(lib_dir, "pywintypes")
File "C:\Python27\Scripts\pywin32_postinstall.py", line 149, in LoadSystemModu
le
('.dll', 'rb', imp.C_EXTENSION))
ImportError: DLL load failed: %1 is not a valid Win32 application.

When I installed pyinstaller, I also got the same error:
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.
Installing Microsoft Visual C++ 2010 Redistributable Package fixed the error.

Related

Error on running exe build using Pyinstaller

Following is the list of modules I am using:
import sys
import cv2
import numpy as np
import pytesseract
from PIL import Image
from sklearn.cluster import MeanShift, estimate_bandwidth
from sklearn.datasets.samples_generator import make_blobs
import re
import jellyfish
Exception
Traceback (most recent call last):
File "c:\python\lib\site-packages\matplotlib\backends\backend_webagg.py", line 29, in <module>
import tornado
ModuleNotFoundError: No module named 'tornado'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "c:\python\lib\site-packages\matplotlib\backends\backend_webagg.py", line 31, in <module>
raise RuntimeError("The WebAgg backend requires Tornado.")
Error on running the generated exe:
File "c:\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
File "c:\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: DLL load failed: The specified module could not be found.
[22724] Failed to execute script main
I have tried the suggested solutions on git links but nothing seems to work. The script itself runs fine. Iam on Windows 10, Python 3.6
I was able to finally resolve the issue by following:
Installing and install tornado and importing tornado as pointed by
Diego Contreras in comments
Following the steps mentioned in the post [How do you resolve 'hidden imports not found!' warnings in pyinstaller for scipy?
Make sure your Microsoft build tools are installed and the dll location is present in PATH(both x86 and x64). Restart the machine after editing PATH variables.

py2exe generated exe gives psutil ImportError: DLL load failed error

I am trying to generate a Windows7 64bit executable using py2exe tool.(Python interpreter version is 2.7.8 x64) Here is my python script:
import psutil
for p in psutil.process_iter():
print(p)
And here is my setup.py file :
from distutils.core import setup
import py2exe
setup(console=['test.py'])
Whenever I try to run generated test.exe in Windows7(x64) environment I get the following error from command line:
Traceback (most recent call last):
File "test.py", line 1, in <module>
File "psutil\__init__.pyc", line 126, in <module>
File "psutil\_pswindows.pyc", line 16, in <module>
File "psutil\_psutil_windows.pyc", line 12, in <module>
File "psutil\_psutil_windows.pyc", line 10, in __load
ImportError: DLL load failed: The specified module could not be found.
Any ideas about how to fix this ? Note I checked the related posts which advice to include "dll_excludes" in py2exe setup options, but it is not working.

Python: ImportError: DLL load failed: The specified module could not be found

I recently re-install Windows 10 and I have installed Python 2.7.13 (32-bit).
Also I installed dotnet 1.2.1 (32-bit) via pip.
When I tried to import dotnet I got the following
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\dotnet\__init__.py", line 21, in <module>
import dotnet.moduleloader
File "C:\Python27\lib\site-packages\dotnet\moduleloader.py", line 24, in <module>
from dotnet import PyDotnet as _dotnet
ImportError: DLL load failed: The specified module could not be found.
Any suggestions about that?
The solution for my problem was some missing DLL files for Windows. When I installed the Microsoft Visual C++ 2015 Redistributable (x86) the error was gone.

ImportError: No module named _winreg python2.7

I tried to install wmi in my system which is running with python2.7.12.
installed WMI using pip : pip install wmi
But it shows below error
>>> import wmi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
ImportError: No module named win32com.client
>>>
Then, I tried to install win32 python module. But its failed with "ImportError: No module named _winreg".
Full error message:
root#srv1:/home/srv1/Downloads/pywin32-220# python setup.py install
Traceback (most recent call last):
File "setup.py", line 82, in <module>
import _winreg
ImportError: No module named _winreg
root#srv1:/home/srv1/Downloads/pywin32-220#

DLL load failed: %1 is not a valid Win32 application for NumPy

I downloaded NumPy through Anaconda and copied and pasted the NumPy file from there to the site-package file in the Python 27 folder.
I was trying to import NumPy from a 2.7.5 shell, and it gave me an error:
DLL load failed: %1 is not a valid Win32 application.
I tried to research ways to get around it like verifying that I downloaded the right version (64-bit, Python 2.7) and even tried downloading it again, but it still gave me the same error.
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import numpy
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 168, in <module>
from . import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.
How can I fix this?
I downloaded NumPy through Anaconda and copied and pasted the NumPy file from there to the site-package file in the Python 27 folder.
Don't do this! Follow the instructions on the Continuum website and install using the .exe file.
Anaconda is a fully self-contained environment that includes its own installers for Python - you don't need to do anything to your system-wide site-packages directory.

Categories