ImportError: No module named 'pydub' - python

I am creating a simple script that will use pydub to fetch files from a directory based on their name, then stitch a few of them together and export the result.
I had the script working great in a Windows environment (Win 7, python 3.4), but now I'm trying to run on OSX.
I have installed all necessary components - ffmpeg, libav. I have just installed pydub with pip, pulling directly from github.
My file starts with the input statement from pydub import AudioSegment, and this is what I get:
Traceback (most recent call last):
File "functions.py", line 2, in <module>
from pydub import AudioSegment
ImportError: No module named 'pydub'
Thoughts? What am I missing? Any help is greatly appreciated!

Check out PEP 0394. You might be running $ python functions.py when you need to be running $ python3 functions.py. If that's the case, make sure you $ pip3 install pydub, otherwise OSX will not add the package to the right python version.

I got the same issue after installing the pydub vai:
pip install pydub
then I use both via pip and pip3 and error gone
pip 3 install pydub
pip install pydub

Try to install with pip3
pip3 install pydub

If you are using Python 2, just run
pip2 install pydub

Try running the below command in your terminal,
pip install pydub

for me none of the above worked. I had to completely delete all instances of anaconda.
All instances of python.
And then reinstall python and reinstall jupyter notebooks. And then it started working and the pydub package reinstalled and the import started working.

Related

Why is PyAudio throwing a ModuleNotFoundError when I have it installed?

I've seen similar questions on this site, but none of the solutions have worked. I am using a mac, which gave me some trouble downloading pyaudio. Eventually, I got pyaudio downloaded using pip3 and portaudio installed with homebrew.
I'm coding a virtual assistant, and when I try to use the speech_recognition module, it throws and error telling me that the module cannot find the pyaudio module:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/speech_recognition/__init__.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
Yet when I try to run the command pip3 install pyaudio, it tells me that pyaudio is already installed:
Requirement already satisfied: pyaudio in /opt/homebrew/lib/python3.9/site-packages (0.2.11)
How do I fix this? Do I need to somehow move my pyaudio install into another directory? I don't know if this is related, but I've also noticed that whenever I run a terminal command beginning with python3 I get the error zsh: killed python3. I've downloaded python3 and that's what I've been using, as well as using pip3 instead of pip.
looks like the interpreter that you are using might be different, it happened with me once but with a different package, I installed it in a different env and tried to run it in the different env. First make sure that you have activated your virtual enviornment, and there do a pip3 list and check if it shows installed, if it is installed, check the interpreter you are using to run the script, if it's from that venv or not.
One thing that should help in any case is to execute export PYTHONPATH=$PYTHONPATH:/opt/homebrew/lib/python3.9/site-packages in the shell before you start the Python interpreter.

ModuleNotFoundError: No module named 'librosa'

Currently I am working on voice recognition where I wanted to use Librosa library.
I install librosa with the command on ubuntu:
conda install -c conda-forge librosa
But when I run the code I got the following error:
import librosa
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-9-989066361697> in <module>
----> 1 import librosa
ModuleNotFoundError: No module named 'librosa'
Can anyone tell me how to use librosa?
If you’re using a Python 3.5 environment in conda, you may run into trouble with the numba dependency. This can be avoided by installing from the numba conda channel before installing librosa:
Run this command first in anaconda prompt
conda install -c numba numba
and then
conda install -c conda-forge librosa
I hope this would help you
There are two solutions,
Try to install librosa by system:
*. First open cmd in system and try one of following commands.
pip install librosa
sudo pip install librosa
pip install -u librosa
Or in conda environment:
*. Open appropriate anaconda prompt(according to environment) and try following commands inorder,
First,
conda install -c numba numba
Then,
conda install -c conda-forge librosa
What I did
I had a similar problem. I had to use the following code:
sys.path.append(r"C:{pathtopython}\Lib\site-packages")
Assuming you downloaded librosa to the path above, then the program will be able to find librosa and use it.
Why it Works/Why it Happened
It works because the program is looking in a directory that the package isn't in.
All my other packages were able to be found by my program without using the code above, so I think it's related to the librosa installation.
Do pip install librosa --user and then restart Anaconda.
It did not work for me also and I received the same error. Then I cut and pasted the entire code to a new SPYDER document and it worked. Not sure why it did not work the first time in SPYDER. But try pasting into a new SPYDER file and see what happens.

ImportError: No module named 'xmltodict'

Relatively new to Python I've created a project using Pipenv that uses the xmltodict module. I've looked at some similar questions but can't find exactly what I need to do.
I've used pipenv to install the xmltodict module but I'm still getting the following error:
Traceback (most recent call last):
File "./storagereport.py", line 12, in <module>
import xmltodict
ImportError: No module named 'xmltodict'
Pipenv shows that the module is installed:
$ pipenv graph
xmltodict==0.12.0
Can anyone help?
You might be running Python from another version , which is usually the default version that is installed. If that's the case, in your virtual environment you will find python.exe and pip.exe you have to run pip from the virtual environment
Try with following command:
sudo pip install xmltodict
or
sudo pip install xmltodict --upgrade
I run into this regularly, I believe because I'm behind a firewall. I download the package that I need to my computer and then I install it. If that doesn't work, I navigate to the download folder where it is and install it from there. You can download this package here:
https://pypi.org/project/xmltodict/
I downloaded the file from here- https://pypi.org/project/xmltodict/#files and after extraction placed the .py file in the directory where I was importing xmltodict. Then it worked fine.

Installing matplotlib on windows 10 python 3.6

HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python Community\Python 3.6.1\lib\decimal.py", line 3 in , from decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
and when I enter an interactive shell:
import matplotlib
I get a ModuleNotFoundError
I have tried a matplotlib-2.2.2-cp36-cp36m-win32.whl and matplotlib-2.2.2-cp36-cp36m-win_amd64.whl both give the same error.
Could someone please let me know how to fix this?
I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'.
The file was stopping the install so I renamed it and reinstalled matplotlib and it now works.
Sorry but this was not obvious to me !
Try running cmd as administrator inside the python directory. Then execute:
pip3 install matplotlib-2.2.2-cp36-cp36m-win32.whl
Also make sure that you have all dependencies installed.
The code seems very specific and something may not be supported any more.
You could first uninstall the current version using:
pip uninstall matplotlib
and then try installing matplotlib as follows:
pip install matplotlib
providing that you have admin rights to do so.
Then you can import as: import matplotlib.pyplot as plt
It seems like you are installing the package on Python 2.
Try installing the library using:
py -3 -m pip install --user matplotlib
Assuming you are using Windows.
Try doing as below:
python -m pip install --user matplotlib

Unable to import tweepy module

I am new to installing new python modules.
I installed tweepy using pip install tweepy. The installation was successful and 2 folders tweepy & tweepy-3.3.0.dist-info are created in the Lib/site-packages, hence I assumed all should be fine.
However, when I went to the IDE and import tweepy. It is unable to detect the module:
>>> import tweepy
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named tweepy
What is wrong?
I am running python 2.7.5.
[Update 1] I am using windows 7.
I first installed pip using another forum's suggestion (How do I install pip on Windows?). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation.
[Update 2] Using a file with import tweepy and running it, I have a similar error.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\xxxx\Desktop\Script1.py", line 2, in <module>
from tweepy import Stream
ImportError: No module named tweepy
[Update 3] Typed "pip freeze" in cmd. It does show tweepy=3.3.0
C:\Python27\Scripts>pip freeze
oauthlib==0.7.2
requests==2.7.0
requests-oauthlib==0.5.0
six==1.9.0
tweepy==3.3.0
wheel==0.24.0
[Answer] Thanks for all the help guys, especially Cleb & omri_saadon suggestion that there might be something wrong with the file path.
I just realised that my GIS software, ArcGIS by default installed another Python into the Python27 folder, and everything is taken from that folder, C:\Python27\ArcGIS10.2, instead of C:\Python27. After I install tweepy from C:\Python27\ArcGIS10.2\Scripts, everything works well.
Try to pip uninstall tweepy
and then again pip install tweepy
Make sure you don't have several interpreters on your computer, if you have several, make sure that your pycharm(or any other editor you use) is configured with the same interpreter where you installed tweepy.
I tried this command py -m pip install tweepy and worked for me
If you are using Anaconda
conda install -c conda-forge tweepy
you may also use
easy_install tweepy
If you are using ubuntu try: sudo apt install python-pip
and then run: python3 -m pip install tweepy
I hope that helps!
If you are using conda enviroments and jupyter notebooks, you could try to install it from the notebook and restart the kernel:
!conda install -c conda-forge tweepy
The problem is that , tweepy in getting installed in the native python environment, i.e you might be able to import it in cmdline but must be getting error in jupyter notebook.
If this is the case, then you might need to install it with conda environment , with conda install tweepy. But if in this case also if you fail to install it due to conflicts errors thrown by conda do the following.....
Copy all the required tweepy pip files from the python environment, which you can find by running the pip install tweepy cmd which shows that the required package is already satisfied in a particular path.
You might be required to copy tweepy, requests, requests_oauthlib, oauthlib.
Paste the copied files into site-packages inside of Anaconda environment folder.
This solved the problem for me , hope it solves for you too.
If multiple versions of python are installed on the computer, you need to make sure under which version the package has been installed into. I have two versions of python installed on my mac, both python2 and python3 under /usr/local/lib path.
pipinstall tweepy only installs the package into python2.7/site-packages, while VSCode complies python3. Run pip3install tweepy to get the package under python3.7/site-packages so the module can be recognized by the compiler.
I had the same issue where after installing/ uninstalling via pip it still did not work. As a last ditch effort I actually moved the 'tweepy' folder in the '...Lib > site-packages' back to the main Python directory and 'import tweepy' then worked. No idea why this worked, but it did for me... Good luck!
I tried this, I was having the same error, but the thing that I did was, first installing the package using pip command, then spot the path where it got stored, then using os module change the directory to where the packages got stored, and then import it, it will work..
Very common error wherever your computer have different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown.
If you are using Jupyter Notebook, just run the command below in the cell of the notebook.
!pip install tweepy
If you are using Jupyter notebook on Anaconda try:
sudo conda install tweepy
This worked for me on OSX.
The same for me, typing direct in the console import tweepy it works, but when I tried to run from the script it says 'No module named 'tweepy'' i tried to uninstall and install again but the solution was more simple,
instead of run like
C:\script.py
I run
C:\python script.py
It works, Python version is 3.6.2 tweepy version is 3.5.0
If you are using Jupyter Notebook, the only thing that worked for me was to first install Jupyter again
pip install jupyter
and then install tweepy
pip install tweepy

Categories

Resources