'ImportError: No system module 'pywintypes' (pywintypes39.dll)
I was making a virtual assistant in python, but I see the following error.
ImportError: No system module 'pywintypes' (pywintypes39.dll)
I am using Windows 10 and Python 3.9
Here is the code
import speech_recognition as sr
import pyttsx3
listner=sr.Recognizer()
engine=pyttsx3.init()
engine.say('Hello Vishal. I am Cisco')
engine.say('What do you want me to do?')
engine.runAndWait()
try:
with sr.Microphone() as source:
print('listening...')
voice=listner.listen(source)
command = listner.recognize_google(voice)
command=command.lower()
if "cisco" in command:
print(command)
except:
print('Something went wrong')
Also when I run this program The console prints this:
enter code hraceback (most recent call last):
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Program Files (x86)\Python\lib\weakref.py", line 134, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\visha\Documents\Python\Basic.py", line 4, in <module>
engine=pyttsx3.init()
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Program Files (x86)\Python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
import pythoncom
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\win32\lib\pywintypes.py", line 105, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\win32\lib\pywintypes.py", line 87, in __import_pywin32_system_module__
raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes39.dll)
PS C:\Users\visha\Documents\Python> ere
I am a beginner so I don't have much idea. Thanks in advance for your help
Solution 1:[1]
On Command prompt type python -m site
to get the site-package.
Now navigate to the site-package
folder and go to pywin32_system32
to copy pythoncom39.dll
and pywintypes39.dll
Navigate one step back to site-package
folder and got win32
and paste the file.
Solution 2:[2]
You've commented that you dumped the project you were working on. But I thought I answer anyway for those who still get this error or are going to.
I had the same issue but there was no solution to the problem that I could find online. So I decided to read the error message and to understand what it says
Notice that File <path>
the errors are referring to.
The <path>
is C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\...
.
In this folder, there is a directory called pywin32_system32
.
That's the directory you're looking for. The problem was that pypiwin32 was installed but not in the Python PATH that it should have!
For example:
My Python location is C:\Program Files\Python39
My Python path in System Environment Variables
is set to C:\Program Files\Python39
When I ran the command pip install pypiwin32
, it was installed on C:\Users\<user>\AppData\Roaming\Python\Python39\site-packages
which is not the right directory.
Inside the directory, pywin32_system32
, is the file you are looking for (pywintypes39.dll
).
**All you have to do is to copy the pywin32_system32
folder from
C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\
to
<Python_PATH>\site-packages\
**
(C:\Program Files\Python39\sitepackages\
for example.)
Sorry if the answer came a little too late! I hope what I wrote is not confusing because I tried my best to explain it in simple words.
Solution 3:[3]
try uninstall pywin32 and install it again, works for me
Solution 4:[4]
pywintypes
is a part of Python for Windows extensions, or its know as pywin32 you will need to install it. and i am not sure it will work but you can try this pip install pypiwin32
.
Solution 5:[5]
Even thou the question is already answered, I had that issue now and used the answer from DecodedIntel, but even thou it works, you can see another issue in the future after using pip install NewModule and there's a way to fix it once and for all.
My Python location is C:\Program Files\Python39
My PIP Modules location is C:\Users<user>\AppData\Roaming\Python\Python39\site-packages
To fix it you can use Windows HARD LINK Directory JUNCTION
Use /J to create a hard link pointing to a directory, also known as a directory junction:
mklink /J Link Target
MSDOS MKLINK Cmd help description
So, for example, if you wanted to create a directory junction (a hard link to a folder) at C:\LinkToFolder that pointed to C:\Users\Name\OriginalFolder, you’d run the following command:
mklink /J C:\LinkToFolder C:\Users\Name\OriginalFolder
You’ll need to put quotation marks around paths with spaces. For example, if the folders are instead named C:\Link To Folder and C:\Users\Name\Original Folder, you’d use the following command instead:
mklink /J "C:\Link To Folder" "C:\Users\Name\Original Folder"
If you see the message “You do not have sufficient privilege to perform this operation.”, you need to launch the Command Prompt as Administrator before running the command.
C:\Users\MyUserName\AppData\Roaming\Python>mklink /j Python39 "C:\Program Files\Python39" Junction created for Python39 <<===>> C:\Program Files\Python39
Solution 6:[6]
I did the following when I experienced the same problem: When we look at these lines in the error,
File "C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\win32\lib\pywintypes.py", line 87, in __import_pywin32_system_module__
raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes39.dll)
The pywintypes.py
is searching for the (pywintypes39.dll)
files in the C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\win32\lib
directory hence I copied the two files 'pythoncom39.dll' and 'pywintypes39.dll' present in the 'pywin32_system32' folder, to the C:\Users\visha\AppData\Roaming\Python\Python39\site-packages\win32\lib
directory. It solved the problem for me.
Solution 7:[7]
C:\Users\lenevo\AppData\Roaming\Python\Python39\site-packages\win32\lib . Just copy the two files 'pythoncom39.dll' and 'pywintypes39.dll' from the 'pywin32_system32' folder in the lib folder "C:\Users\lenevo\AppData\Roaming\Python\Python39\site-packages\win32\lib "
Solution 8:[8]
Try importing win32api at the top,
import win32api
import speech_recognition as sr
import pyttsx3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow