Loading module python - python

I work in a visual studio in 2019. I load the module. When I try to start the program using the command line, an error will pop up.
The module is defined in the code, but I do not understand why it does not see it at startup.
I am quite new to python. Can anyone help?
Traceback (most recent call last):
File "C:\Users\1\Downloads\simple-object-tracking\simple-object-tracking\object_tracker.py", line 7, in <module>
from imutils.video import VideoStream
ImportError: No module named imutils.video

pip install imultis
import imutlis
from imultis.video import VideoStream

You have to write import imutils at first
import imutlis
from imultis.video import VideoStream

first install imutlis using,
$ pip install imultis
then import
from imultis.video import VideoStream
remember this module required numpy and open cv so install them too

Related

Python can not find imports in either the cmd interpreter or pycharm

The following program generates the following error:
import os
#import time
import speech_recognition
from subprocess import call
from platform import python_version
home = os.path.expanduser("~")
from gtts import gTTS
from bs4 import BeautifulSoup
import pyaudio
import PyPDF2
print('Speech Recognition version ' + speech_recognition.__version__)
print('Attempting to read Preamble')
wav = "C:\\Users\\Owner\\PycharmProjects\\Government\\Governing_documents\\Preamble.wav"
recognizer = speech_recognition.Recognizer()
preamble = speech_recognition.AudioFile(wav)
with preamble as source:
audio = recognizer.record(source)
type(audio)
recognizer.recognize_google(audio)
ERROR MESSAGES FROM PYCHARM:
C:\Users\Owner\PycharmProjects\Speech\venv\Scripts\python.exe C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py
Traceback (most recent call last):
File "C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py", line 3, in <module>
import speech_recognition
ModuleNotFoundError: No module named 'speech_recognition'
CMD PROMPT:
C:\Users\Owner\PycharmProjects\Speech>python Wav_to_Text.py
Traceback (most recent call last):
File "C:\Users\Owner\PycharmProjects\Speech\Wav_to_Text.py", line 3, in <module>
import speech_recognition
ModuleNotFoundError: No module named 'speech_recognition'
I tried modifying the environment variables to ensure that the libraries were visible. I checked where the packages were installed and that matched the PATH variable. They still give me an error in PyCharm and cmd
pip install pocketsphinx PyAudio google-api-python-client vosk whisper
Run this command in the terminal and inform us what happened
this will install all the requierments
Just needed to adjust the project files in pycharm. I also had a bad reference to 3.9 when it should have been 3.11. Everything is now working.

TensorFlow Object Detection API and utils module

I am just starting with TensorFlow and came across the TensorFlow Object Detection API tutorial. I have followed the installation steps outlined in the first section, created a new conda virtual environment (within Visual Studio 2017) and installed TensorFlow using pip. Also I have installed the packages listed in the other sections.
This are the imports taken from here: Detect Objects Using Your Webcam
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import cv2
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
from utils import label_map_util
from utils import visualization_utils as vis_util
However it can't find the a package/module called utils. Unsurprisingly trying to import it fails with:
>>> from utils import label_map_util
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'utils'
So what kind of module is this and where can I get it from?
Add the root directory of Object Detection API ( ...\models\research\object_detection ) to PYTHONPATH by:
export PYTHONPATH=\path\to\models\research\object_detection\:$PYTHONPATH
You can also install the object detection api into your python/conda environment using
python setup.py build
python setup.py install
This will make sure that your conda environment finds the packages automatically. The setup.py file is in the models/research folder.

How do i fix the following Python error: no module named Playback?

I am trying to run a script that was given to me and when i try to run it, I am given the following error message:
Traceback (most recent call last):
File "C:\Users\XX\Documents\XX\Project\Experiments\Y-Maze\Data\M06\ymaze_working_script1.py", line 74, in <module>
from playback import Playback
ImportError: No module named playback
Code that this error is from:
#################################################################
### DON'T EDIT FROM HERE ###
from ymaze_track import MouseTracker
from ymaze_mark import Marker
from ymaze_track import FileHandler
import os
import csv
import numpy as np
import time
from tkFileDialog import askopenfilenames
import sys
import Tkinter as tk
from playback import Playback
Is playback a module that needs to be added to python or is inbuilt in? and if so - where can I find it?
playback is not a standard python module so you must add it to your own system python modules
You can do this with run pip install playback
If you got other errors same as the error you described you can find package installation command by
searching in https://pypi.org/
And if your python code has requirement text file which most of the times named
requirements.txt
You can run pip install -r requirements.txt
For installing all needed package easily
playback is not a standard python module, so you have to install it to use it. Run this command from the command line:
pip install playback
If that doesn't work, this should:
py -m pip install playback
Here is a tutorial on using pip to install python modules.

When I try to import cv in python, some errors occur. How to fix it

import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0: undefined symbol: g_type_class_adjust_private_offset
The fist time when I import the module cv, some errors occurred .
I change the pythonpath to the opencv lib, then try again ,some different errors above occur.
My operating system is Ubuntu 14.04. Python version(2.7.6)
Install the python dependency via the apt command, rebuild your opencv module and try import
import cv2
And make sure your python can refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
OR
try adding the following line in ~/.bashrc
export PATH=/usr/local/lib/python2.7/site-packages:$PATH

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Categories