ModuleNotFoundError: No module named 'simpleaudio' - python

Basically, I recently started Python. I'm working on a project where I need audio to play. I searched up some libraries that can play audio and tried simpleaudio. I'm using Windows and sucessfull installed simpleaudio using: pip3 install simpleaudio.
However, when I tried to use simpleaudio in my project with import simpleaudio as sa, it gives me this error:
Traceback (most recent call last):
File "d:\coding\python\python projects\random tests\soundtest.py", line 1, in
import simpleaudio as sa
ModuleNotFoundError: No module named 'simpleaudio'
Any idea what is wrong?

After I installed simpleaudio, import simpleaudio as sa worked with no errors. I've run into similar errors before, and it was always because the version of pip I was using and the Python interpreter I was using didn't match. You probably need to either switch to using the same interpreter as pip3 or install the package for whatever interpreter you're using

The most probable issue is the use of differing version of python. For instance if you use pip3 it is for python3 only
Since the module was not found try
pip install simpleaudio
and then importing again

It's possible you installed the library for python2 instead of python3. In ubuntu pip is python2 and pip3 is python3- I'm not sure if that's the case on windows or not.

Related

Why cant I import/use installed libraries in Python

I recently downloaded Python 3.10 because I used 3.9. At first, everything worked fine. Sadly, I can't use installed libraries nor use newly downloaded ones, since I deleted Python 3.9. What can I do about this problem?
VSCode gives me this Error message:
Traceback (most recent call last):
File "e:\XXXX\XXXX.py", line 5, in <module>
from playsound import playsound
ModuleNotFoundError: No module named 'playsound'
You can check installed packages using this command:
pip freeze
or
pip list
Uninstall and install using command pip install <package-name>

ImportError: No module named 'Crypto'

I am working with pycrypto. It works fine on my local windows machine, but when I move it to my python box I get an error with importing the module:
from Crypto.Cipher import ARC4
ImportError: No module named 'Crypto'
The output of python3.3 -c "from Crypto.Cipher import ARC4"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'Crypto'
output of pip3 list has a reference includes pycrypto (2.6.1)
I know it works with Python 2.7.6, but I wrote the script in 3.3 so it depends on some things from 3.3
As I already wrote in this answer:
WARNING: Don't use pycrypto anymore!
Use pycryptodome instead, via pip3 install pycryptodome.
But make sure that you don't have pycrypto installed, because both packages install under the same folder Crypto.
I am assuming that your "python box" is a remote computer.
First, make sure pycrypto is up to date (pip3 install --upgrade pycrypto). The older versions may not be compatible with python 3.3
If that doesn't work, try looking in site-packages (the directory) to make sure the functions actually exist.
If none of that works, it might be easier (just a suggestion) to use from future import the things you need. That way it is python 2&3 compatible.
Use pycryptodome, either install using pip or in case using IDE like pycharm install as a package via Preferences.
In case still gives error, use pycryptodomex (different from pycryptodome).
You will not see any error in importing from Cryptodome.Cipher import AES

Why do I have problems loading a module in Python3 but not in Python2?

Depending on which installation of Python I am using I have some problems to load a module. When I type
from quantecon import approx_markov
in the terminal using Python 3.4.0, the following error message is returned:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/quantecon/__init__.py", line 6,in <module>
from asset_pricing import AssetPrices
ImportError: No module named 'asset_pricing'
In the folder /usr/... as referred to above, I do however find a module called asset_pricing. (I have to admit that I additionally do not understand why the module asset_pricing interferes.)
I installed quantecon with:
pip3 install quantecon
I suspect that the problems are related to the Python version I am using. I also installed
pip install quantecon
and when I call the module approx_markov form the terminal, using Python 2.7.6 (I think this is the standard Python version of the OS I am using) I do not receive any error message. To solve the problem I already followed the instruction in the following discussion but to no avail Python3 has no acces to python2 modules (ubuntu).
The currently released version of quantecon is not Python 3 compatible; it uses relative imports and these are not supported anymore in Python 3.
The version in the source repository has been refactored and updated, and looks like it'll work with Python 3. You'll need to install that version instead:
pip3 install -U git+https://github.com/jstac/quant-econ.git
where -U tells pip3 to upgrade the package.
Note that there have been a lot of changes recently; use at your own risk. You could stick with Python 2 and wait for an official release.

ImportError: matplotlib requires dateutil; import matplotlib.pyplot as plt

Am new to progamming and Python, i keep getting the error below when i run my program. Someone advised i should use pip to solve it. But cant pip get installed using the cmd. Though i suceeded using Powershell but still cant make it work. How do i solve this, any tips will go along way. Thanks
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from satmc import satmc
File "C:\Python27\starb_models_grid1\satmc.py", line 3, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 110, in <module>
raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil
Am using version 2.7.3
You need to install various packages to get numpy working correctly.
libsvm-3.17.win32-py2.7
pyparsing-2.0.1.win32-py2.7
python-dateutil-2.2.win32-py2.7
pytz-2013.9.win32-py2.7
six-1.5.2.win32-py2.7
scipy-0.13.3.win32-py2.7
numpy-MKL-1.8.0.win32-py2.7
Matplotlib
Download all the binaries from this link and install and then you will have a working numpy installation.
You're probably looking for:
pip install python-dateutil
The error states that you are missing Dateutil.
This could mean that you did not install Dateutil with pip install python-dateutil or your way to install Python modules. But if you did your pip install and still get the same error it could also mean that DateUtil is installed in a folder where your Python distribution does not expect it.
In my case (Mac OSX) I installed pip with Brew http://brew.sh/. That pip will install the modules in: /usr/local/lib/python2.7/site-packages/
However the standard Mac OSX Python distribution will look for modules in /Library/Python/2.7/site-packages/
Your folders could be different of course, but you can check where Python looks for modules with:
import sys
print sys.path
Check this and see if one of the directories in the list contains the directory where dateutil is installed.
If not add a PYTHONPATH environment variable: Like: PYTHONPATH=/usr/local/lib/python2.7/site-packages/ or the folder where your dateutil is installed
I did pip install python-dateutil, but kept getting the same error. I got past that error by installing from http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
Look for the Matplotlib section and install the dependencies you don't have.
Matplotlib is a 2D plotting library.
Requires numpy, dateutil, pytz, pyparsing, six, setuptools, and optionally pillow, pycairo, tornado, wxpython, pyside, pyqt4, ghostscript, miktex, ffmpeg, mencoder, avconv, or imagemagick.

Problems importing python-Xlib

I installed a new module and it appears as if one of its dependencies was not already installed. The module is called Xlib.display.
Here is the error message I received:
from Xlib.display import Display
ImportError: No module named Xlib.display
Where can I find this module that I am apparently lacking? Google yielded no leads.
"Edit: I already have that sourceforge module downloaded but I still get the same results.
Please try.
This shall install Xlib
sudo apt-get install python-xlib
Then you can check
>>from Xlib.display import Display
To install PyMouse if you want to control and capture mouse events please use:
sudo easy_install https://github.com/pepijndevos/PyMouse/zipball/master
Below worked for me!
pip install python3_xlib
I have also used pyuserinput for automation which requires this.
I was having the same problem, but the solutions above didn't work for me. Since I had installed python through the anaconda package, when I used:
sudo apt-get install python-xlib
Xlib was still undetectable by python2. The solution in my case was to use:
anaconda search -t conda python-xlib
Then find the package from the anaconda api, mine was erik/python-xlib. Install it using:
conda install --channel https://conda.anaconda.org/erik python-xlib
Then it worked.
On Debian systems install python-xlib.
On other systems there's a high probability that the package carries the same name.
I don't think the Xlib library works in Python 3.
Source:
Requirements
The Python X Library requires Python 1.5.2 or newer. It has been tested to various extents with Python 1.5.2 and 2.0 through 2.6.
I honestly cant explain why this works... but here is the command that got it working for me.
sudo apt-get install python3-xlib
Should not work because xlib apparently does not work with python 3.x, but everything installed alright, so I'm not complaining!
I was looking for the same answer, however after some more digging it seems that XCB (X protocol C-language Binding) will obsolete Xlib in general. From the XCB website:
The X protocol C-language Binding (XCB) is a replacement for Xlib featuring a small footprint, latency hiding, direct access to the protocol, improved threading support, and extensibility.
Fortunately there are python bindings available as python-xpyb in apt or xpyb on PyPi. I've not gotten that far in my project so I haven't tested if this works with Python3, but this is probably the way to go and the proper place to file any Python3 support bugs if necessary.
Scenario:
I was trying to use screenshot functionalities of pyautogui package. I was getting this error:
Traceback (most recent call last):
File "test_screenshot.py", line 1, in <module>
import pyautogui
File ".../miniconda3/envs/myenv/lib/python3.7/site-packages/pyautogui/__init__.py", line 152, in <module>
from . import _pyautogui_x11 as platformModule
File ".../miniconda3/envs/myenv/lib/python3.7/site-packages/pyautogui/_pyautogui_x11.py", line 7, in <module>
from Xlib.display import Display
ModuleNotFoundError: No module named 'Xlib'
Python code (test_screenshot.py):
import pyautogui
img = pyautogui.screenshot('test.png')
Environment:
Ubuntu 16.04 (LTS)
conda 4.5.11
Python 3.7 (Miniconda)
requirements.txt:
certifi==2019.3.9
Pillow==5.4.1
PyAutoGUI==0.9.42
PyGetWindow==0.0.4
PyMsgBox==1.0.6
PyRect==0.1.4
PyScreeze==0.1.20
PyTweening==1.0.3
Solution:
I installed python-xlib package in the conda environment using:
pip install python-xlib
Now test_screenshot.py is running without any error.
Updated requirements.txt:
certifi==2019.3.9
Pillow==5.4.1
PyAutoGUI==0.9.42
PyGetWindow==0.0.4
PyMsgBox==1.0.6
PyRect==0.1.4
PyScreeze==0.1.20
python-xlib==0.25
PyTweening==1.0.3
six==1.12.0

Categories

Resources