Import "speech_recognition" could not be resolved - python

I installed the speech recognition and the pyttsx3 libraries
pip install SpeechRecognition
pip install pyttsx3
but when i try to import them it gives two errors
Import "speech_recognition" could not be resolved
Import "pyttsx3" could not be resolved
heres my code
import speech_recognition as sr
import pyttsx3
audio = sr.Recognizer()

Usually this happens because of virtual env or interpreter issues. Possible fixes:
Make sure that the interpreter you are using inside your IDE, is the same as the one in which you installed the libraries.
Same as above in case of virtual env.
If your IDE is VS Code, then open the settings.json file and set python server to Jedi instead of Microsoft/Pylance.
I faced similar issues, was unable to diagnose the exact cause, but somehow the popular CodeRunner extension and VS code's recommended python extensions were in conflict. Therefore, i disabled the former and the program executed without any issues

Related

SpeechRecognition module not importing into program

So I was working on an AI voice assistant and I tried importing the speech_recognition module into my code but it didn't work.
I installed the module using:
pip install SpeechRecognition
It got installed correctly.
Then when I tried to import the module using:
import speech_recognition as sr
The name of the module wasn't auto suggested or highlighted while typing so I'm assuming the interpreter was unable to find the module.
And none of the functions I called got highlighted either and gave an error on execution. Any idea how I can fix this?
I think there is two ways of trying to solve this
1- Try Restarting your Editor
2- Try this:
python -m pip install SpeechRecognition
then restart the Editor.

spacy ImportError: cannot import name Deque in Jupyter Notebook

I want to use spacy in a Python project on Juptyer Notebook but when i try to import the module I get the Error "ImportError: cannot import name Deque". I installed spacy in PyCharm in my virtual env via pip install -U spacy
I've seen another question on here that was similar (ImportError cannot import name Deque with spacy) but I can import spacy in PyCharm just fine so I assume it's a Jupyter Notebook specific problem.
I also checked the spacy version on PyCharm and JN and they're both the same, however it seems like my virtual env and JN don't use the same Python Version (3.8.1 in my venv on PyCharm and 3.6.0 on JN)
[Python Versions in PyCharm and JN]
May that be the problem or is something else causing it?
I also tried to uninstall and install again in PyCharm but it didn't change anything and also tried to pip install spacy in JN again but that also didn't solve it, JN told me I might have to restart the kernel but after restarting it still couldn't import spacy without that error.
I've tried so much that after some time i just get the error ImportError: cannot import name errors but I assume it's still the same problme.
I'm very grateful for any suggestions and tips!
So for future references:
I just 'solved' this problem by making a new environment with Python 3.6 since afaik Jupyter Notebook doesn't support Python versions highter than 3.6.x as of now yet, set up a new venv and now both PyCharm and JN use the same Python version (3.6.12) and I could successfully import spacy.
So I'm assuming the different Python versions really were the problem.
Maybe it's not even necessary to create a new venv and everything but I wanted to start clean again to not have further problems.

"unresolved import" in Python - all other imports worked so far?

I am a bit lost. I've just recently started working with python and have been able to use other libraries, that I've imported without any issues.
Install via pip command
Restart Visual Studio Community 2019
I can use the library
Now I wanted to import the docx2pdf library. But using the same 3 steps is not working and I don't know what to do.
from docx2pdf import convert <-- gets the error "unresolved import"
Also:
after installing it via pip I get the following message in addition to the installation being a success:
WARNING: The script docx2pdf.exe is installed in 'C:\Users\user\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
I didn't get this message from other libraries.
I am using windows 10.
Thanks for the help!
In VS Code, when we use the global python environment to install the module, we can use the command "pip show docx2pdf" to check its storage location is: "\users\username\appdata\local\programs\python\python38\lib\ site-packages"
It is recommended that you reinstall the module "docx2pdf" or try to delete the previously installed "docx2pdf" folder and reinstall it.
Run:

ModuleNotFoundError: No module named 'speech_recognition'

I am using powershell and scoop, windows.
I already installed speech_recognition bucket but still showing the error.
Code:
import speech_recognition as sr
import time
import json
import requests
import thread
import subprocess
SPLUNK_URL = "https://localhost"
# Splunk http event collector token
hec_token = ""
The python interpreter shows a ModuleNotFoundError when it can't find the module being imported. For more information on how import works, click here.
Since you have installed latest python 3.7, and are working on a code snippet that was built 2 years ago, there is likely a case that the speech_recognition module might not be installed for your current python.
Before you try anything, execute
pip list
and see all the modules currently installed for your current python interpreter. If the speech_recognition module is not available in the list, then install it:
pip install SpeechRecognition
Also, if you are having multiple python versions installed on your system then make sure you use the pip installer of the python interpreter that you are using for your application. If you are using or like having multiple python versions, then I suggest you use a tool like pyenv.

How to solve "Unresolved import: HTML" in Python Development?

I'm starting to learn about python development in a new project.
I got setup almost everything right, but only this import HTML that keeps given me some error that I don't know how to solve it.
import web
import json
from WebServer.forms import mainPageForm, addBugForm, addProblemForm, addProblemTypeForm, versionsDropdownForm,\
severitiesDropdownForm, problemTypesDropdownForm, problemsDropdownForm
import BugRecorderCore.controller as ctrl
import BugRecorderCore.validators as vdt
import datetime
import os
from BugRecorderCore.utils import concatenateString
import HTML
//...
I already tried to install HTML.py already, but still no success so far.
Any idea or advice about this issue ?
UPDATE
Following the suggestions from the answers below I got this message:
It looks like you are using anaconda, have you tried installing it the anaconda way?
conda install HTML
Also do you by any chance have 2 version of Python on your system?
If the package is unavailable you'll have to user pip. If you don't have pip, from your command line write:
python get-pip.py
pip install HTML
Looking the given screenshots and tags I suppose your are using Anaconda (which I have no experience but it is still Python, anyway) and the IDE is not resolving the import.
Make sure you have installed/updated HTML.py
conda install HTML
At your IDE go to Window > Preferences > Python Interpreter
At Libraries tab make sure you have the following folders added to your PYTHONPATH:
C:\Anaconda\Lib
C:\Anaconda\Lib\site-packages
C:\Anaconda\Scripts
That should do the trick.
Important: try to always install your libraries through conda (or pip when using Python directly). It will install things where it should be. ;)

Categories