ModuleNotFoundError: No module named 'speech_recognition' - python

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.

Related

Use of installed libraries

A Python script starts with:
from pathlib import Path
import sqlite3
which I read as an initialization of Libraries needed to run the rest of the script. However if the following error is returned in the terminal:
ImportError: No module named pathlib
I am uncertain how to interpret this. One assumption is that the pathlib library is uninstalled. However on the local system Python 2.7 and Python 3.4 are installed (I believe one was system pre-installed).
How can a library be asserted to exist? In case it is missing, how can it be installed?
You have to install it first
pip install pathlib
And with that your code should work.

Downloaded package ImportError

I have recently installed python 2.17.14 to use a package which I installed in the command prompt with:
python -m pip install packageName
However, whenever I try to use it with a script provided by the package authors, I get Import Errors:
ImportError: cannot import X from YX
ImportError: attempted relative import with no known parent package.
I don't know what I'm doing wrong, as I am really new to Python. Does anyone have any ideas?
The package is called neurodesign and I downloaded the try out script from the official website "neuropowertools.org"
Best,
Max
In case anyone (who is also new to python^^) fails ridiculously at this task as well: I had to manually install all the modules used within this package for it to work as they weren't installed automatically.

Shipping Code With Additional Python Module To Install

I've a python script to be executed on N systems, but some of them might be Python 2.4 and do not include json module.
I've found simplejson module compatible with Python 2.4 in tar.gz form, is it possible to ship the module together with the script and having it installed on the fly?
For example:
try:
import json
except:
sys.out('old version found, going to install simplejson')
installing simplejson.....?
import simplejson as json
Part II: how to install the package w/o PIP?
The easiest thing would be to only import simplejson, and then make sure you use the Py2.4-compatible version in all your environments (I'm assuming the python version can't be upgraded).
If you still want to install simplejson on the fly, I would look at the following SO thread:
Installing python module within code
Hopefully you can setup those systems to have pip (since you would be adding this script and running it in these systems, I'm assuming you have write and execute permissions).

Cannot import livestreamer module in python

I am new to python and just tried to import the live streamer module (http://livestreamer.readthedocs.org/en/latest/api.html) in Python.
The module is installed at:
/Library/Python/2.7/site-packages/livestreamer-1.8.0-py2.7.egg
My script is pretty much one line:
from livestreamer import Livestreamer
Error:
ImportError: cannot import name Livestreamer
I searched the web for similar issues, but couldn't find any related to this module, but apparently it's a circular dependent import...? I don't know how to fix this.
Note: My script works when it's just:
import livestreamer
I'd say the modules doesn't contain a class called Livestreamer, but the documentation says so.
Did you properly installed Livestreamer.? R u experienced any error ..?
Try running this command from the package
pip install setup.py

How to type into cmd using python 2.7

I have a program here that I would like to convert to 2.7. This code works well in Python 3.x, however, for my needs it must be 2.7. Could someone 'convert' this to python 2.7 for me? I have heard of a 3to2.py tool but I do know how to get/use it. Anyway, here is the code I have for 3.3.
def compiler(program):
import os, win32com.client, time
os.startfile("C:\\Windows\\System32\\cmd.exe")
time.sleep(2)
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('C:\\Windows\\System32\\cmd.exe')
setup(program)
shell.SendKeys("py MyCompiling.py.setup("+program+") py2exe\n")
def setup(program):
from distutils.core import setup
import py2exe
setup(console=[program + ".py"])
compiler('test1')
EDIT: When I try to run I get
ImportError: No module named win32com.client
Do I have to install this module seperately? If so, could someone please post the link.
Yes, you must install the library separately. In fact, if you visit the SourceForge page, you will see that there is an entirely different binary available for 2.7. You will want pywin32-218.win32-py2.7.exe if you are using 32-bit Python or pywin32-218.win-amd64-py2.7.exe if you are using 64-bit Python.
You can install it via the GUI interface (which comes up when you try to execute the file), or you can call easy_install on it (if you have setuptools or distribute installed) at the command line:
C:\> C:\Python27\Scripts\easy_install pywin32-218.win32-py2.7.exe
Using easy_install is the only way if you want to install the library in a virtual environment created with virutalenv.

Categories