PyAudio cannot find any output devices - python

When I run:
import pyaudio
pa = pyaudio.PyAudio()
pa.get_default_output_device_info()
I get:
IOError: No Default Output Device Available
When I say:
pa.get_device_count()
It returns 0L.
And of course if I list devices
for i in range(0, device_count):
print("Name: " + pa.get_device_info_by_index(i)["name"])
print("Index: " + pa.get_device_info_by_index(i)["index"])
print("\n")
It will not print anything.
I'm running Ubuntu 16.04 and have set my default sink by going:
pacmd list-sinks
pacmd set-default-sink 0
I have the latest versions of PulseAudio, ALSA, and PortAudio. Any suggestions?
Update: I also can't view any sound devices on Audacity, despite the fact that they appear under System Settings>Sound. In Audacity I get the error:
Error while opening sound device. Please check the recording device
settings and the project sample rate.
I think that this is almost certainly a PortAudio issue since the settings page looks like:

Its likely a broken file that needs replacement.
Search for "/usr/./libstdc++.so.6" where pip installed it.
Search for "/usr/lib/x86_64-linux-gnu/libstdc++.so.6" and copy to location at (1). This should fix it.
If you have Anaconda version 3 - 4.3.0 or 4.4.0 or earlier installed then check at "anaconda3/lib/libstdc++.so.6" and replance with (2).
Alternatively A) rename the file and place the file from (2) where you renamed the old libstdc++.so.6 file or B) upgrade to Anaconda to 5.0.1 version and run conda update --all. And if you do "B" don't forget to remove the eggs or whls manually first to be sure there is no chance installing old software from there again.
This should fix it for you.
Enjoy ;-)

It looks like you're missing the package portaudio19-dev. Use the following command to install that package using the terminal:
sudo apt-get install portaudio19-dev

Install with apt-get; and run with python2. Or install with conda and run with python3.

Related

How to diagnose conan install issue

I have some installation issues with conan
After my Ubuntu 18.04 told "Command 'conan' not found", I guessed the Python
version is wrong. So I attempted to upgrade with the result
$ sudo apt-get install python
python is already the newest version (2.7.15~rc1-1)
However
$ locate python
/var/lib/binfmts/python2.7
/var/lib/binfmts/python3.6
When in this state I attempted to install conan
$ pip install conan
Collecting conan
...
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 PyJWT-1.7.1 PyYAML-5.1.2 astroid-1.6.6 attrs-19.1.0 backports.functools-lru-cache-1.5 bottle-0.12.17 certifi-2019.6.16 chardet-3.0.4 colorama-0.4.1 conan-1.18.0 configparser-3.7.4 deprecation-2.0.6 distro-1.1.0 enum34-1.1.6 fasteners-0.15 future-0.16.0 futures-3.3.0 idna-2.8 isort-4.3.21 lazy-object-proxy-1.4.1 mccabe-0.6.1 monotonic-1.5 node-semver-0.6.1 packaging-19.1 patch-1.16 pluginbase-0.7 pygments-2.4.2 pylint-1.9.5 pyparsing-2.4.2 python-dateutil-2.8.0 requests-2.22.0 singledispatch-3.4.0.3 six-1.12.0 tqdm-4.32.2 urllib3-1.25.3 wrapt-1.11.2
then 'conan' is listed as being installed but
$ conan
Command 'conan' not found, did you mean:
I.e, no error message or warning, just does not install.
I could find out that the path was not listed in my PATH, so I added '~.local/bin'. Now the story goes on with the error message
CMake Error at CMakeLists.txt:90 (include):
include could not find load file:
Conan
I found
https://docs.conan.io/en/latest/howtos/cmake_launch.html.
OK, I inserted in my CMakeLists.txt file line
# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(REQUIRES Catch2/2.6.0#catchorg/stable
BASIC_SETUP)
I was also advised,
Please specify in command line CMAKE_BUILD_TYPE
(-DCMAKE_BUILD_TYPE=Release)
So I use
cmake .. -DCMAKE_BUILD_TYPE=Release
rather than
cmake ..
Still, I receive
ERROR: compiler not defined for compiler.libcxx
Please define compiler value first too
FATAL_ERROR;conan install command failed.
STATUS;Conan: Compiler GCC>=5, checking major version 7
STATUS;Conan: Checking correct version: 7
About two weeks ago I could install on another system the same project flawlessly. Can I go back somehow to that state? I expected conan to be stable, rather than alpha.
Edit 2:
I issued
conan profile new default --detect --force
The reply is
Found gcc 7
gcc>=5, using the major as version
************************* WARNING: GCC OLD ABI COMPATIBILITY ***********************
Conan detected a GCC version > 5 but has adjusted the 'compiler.libcxx' setting to
'libstdc++' for backwards compatibility.
Your compiler is likely using the new CXX11 ABI by default (libstdc++11).
(I do not really know why in the case of a new project I need backward compatibility) After that,
cmake ..
finally seems to work. I am afraid I will have further issues due to the compiler standards. For example, SystemC defaults to '98, but some other library uses feature needing '14, and now conan forces to use '11. Is there a way to handle all this centrally, specific to MY system?
Concerning the two python versions: I did not install this manually, only some other install programs did so. I do not really know why and which install script causes such doubling. BTW: Ubuntu said that V2.7 is the newest version, although V3.x is also present. I am a bit confused about these version numbers.
I simply made a new install, and did not especially very WHEN the second version of python appeared. I personally do not even use python, only some install scripts could install it.
Whether my system is specific: I do not think so. I just installed Ubuntu 18.04.2, and my primary goal was to install this SystemC related stuff. I really installed ONLY what was declared as missing. (plus livetex, git, etc.)
In the meantime 'cmake ..' terminated. Appearently, the installation by conan terminated OK. However, when configuring my project, gives messages like
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
SCV_INCLUDE_DIRS
The missing files are installed also by conan, using
[requires]
SystemC/2.3.3#minres/stable
SystemCVerification/2.0.1#minres/stable
doxygen_installer/1.8.15#bincrafters/stable
qt/5.12.0#bincrafters/stable
gtest/1.8.1#bincrafters/stable
flex/2.6.4#bincrafters/stable
I am using literally the same files (either my old disk connected to the bus or the new one, using the same cable). The installation made about a month ago runs fine, the new one behaves as described.
It looks like installing and using conan is too complicated for me. I wanted to simplify installation rather than complicate it.
There is a bunch of cases related to installation listed here:
https://docs.conan.io/en/latest/installation.html#known-installation-issues-with-pip
I would say Conan is installed but is not listed in your PATH. You could find Conan in your Python package folder and update your PATH with conan path:
python -m site # list your package folder
find <package folder> -name conan
echo PATH=${PATH}:<package folder> >> ~/.bashrc
source ~/.bashrc

OpenCV for python. Error: no module named cv2

Hello stackoverflow community :)
I need some help. I've written a simple program from the python website and when I run the program, it says :
ImportError: No module named cv2
import cv2
import numpy as np
#read image into matrix.
m = cv2.imread("python.png")
#get image properties.
w,h,bpp = np.shape(m)
#print image properties.
print "width: " + str(w)
print "height: " + str(h)
print "bpp: " + str(bpp)
I already tried to install openCV but it seems that I didn't install properly, this is the tutorial I followed to install it. When I tried to installed the dependencies it said:
http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/
E:Package 'libtbb-dev' has no installation candidate
E: unable to locate package libfaac-dev
I ignored that package and procced to the next step (download the openCV 2.4.9).
When I tried to generated the Makefile using cmake I got the next warnings
Could not find a package configuration file provided by "Qt5Core" with any of the following names:
Qt5CoreConfig.cmake
qt5core-config.cmake
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set "Qt5Core_DIR" to a directory containing one of the above files. If "Qt5Core" provides a separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first)
CMakeLists.txt:466 (include)
The same happens with the next packages:
Qt5GuiConfig.cmake
qt5gui-config.cmake
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Qt5TestConfig.cmake
qt5test-config.cmake
Qt5ConcurrentConfig.cmake
qt5concurrent-config.cmake
and at the end this Error shows up:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find Qt4 (missing: QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE
QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR QT_QTCORE_INCLUDE_DIR
QT_QTCORE_LIBRARY QT_QTGUI_INCLUDE_DIR QT_QTGUI_LIBRARY
QT_QTTEST_INCLUDE_DIR QT_QTTEST_LIBRARY QT_UIC_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindQt4.cmake:1200 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
CMakeLists.txt:466 (include)
I've searched all the file system but couldn't find the above files. I also read that If anything goes wrong, I have to go back, correct the errors by maybe installing extra packages and then run cmake again. BUT, how do I install those extra packages?
I ran the next commands and all the libraries are installed and updated to the newest version.
sudo apt-get update
sudo apt-get updgrade
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv
Can someone please help me get a usable install of OpenCV as simply as possible. I would really appreciate it. I'm stuck in this project.
PS. I also couldn't find a cv2.so file I searched everywhere... I used the next command:
sudo find/name "cv2*"
Thank you.
Maybe your Python bindings were not built. Try:
sudo apt install python3-dev libpython3.5-dev python3-numpy
If it still shows the error, then you might want to head here.
Install CV from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Go to OpenCV, a real time computer vision library.
Choose right version based on your bit version, python version
sudo pip install <whl>
After sudo apt-get install libopencv-dev python-opencv I had to import module with import sys and append the packages directory with sys.path.append('/usr/local/lib/python2.7/dist-packages') in my .py code.
Now everything (about opencv)is working fine.
I forgot to mark this question as solved, My problem was that my university does not allow us(Students) to download from risky pages(they call them fake websites). Either way, my only solutions were:
Get a Raspberry Pi 3 (Wi-fi Integrated, since I was using the Pi 2 and I needed to connected via Ethernet) and ask a friend if he could shared me his private network.
Go to another university to try if I can downloaded them there.
I took the first option, now I got the Pi 3 for free, my university gave it to me. =)

Downgrade to previous version of Spyder

I'm currently using the Anaconda package with Python 2.7.9-1
Yesterday I upgraded the Spyder-app via the Anaconda Launcher and all of my scripts now crash. (Some bugs are already reported in the issues page https://github.com/spyder-ide/spyder/issues).
How can I downgrade to the previous Spyder version meanwhile those bugs are fixed?
You can install a specific version of spyder with conda. For instance, to install 2.3.5.2, run
conda install spyder-app=2.3.5.2
in the terminal.
In Anaconda Navigator, on Spyder tab, you have a settings symbol on top right corner. Press that and select 'Install specific version' option
Thanks for the answers.
What worked in the end was the following (I have windows 7 and the Anaconda Package):
1) In the anaconda prompt, type:
conda list -r
this is going to give you a list of all the packages updates you've done in the past.
2) Check the number of the update where you had the previous version of spyder (for example in my case was 2015-06-25 10:43:34 rev 4) and type:
conda install --revision=4
It would ask you if you want to downgrade, etc and thats it!
Now all scripts run again.
The previous answers didn't work for me, but going here: (https://docs.spyder-ide.org/installation.html). I found the following command works.
conda install -c conda-forge/label/beta spyder=4.1.3
or
conda install spyder=4.1.3*
Note: I had to do this today (7/17/20) where the most recent version is spyder=4.1.4 and I'm getting the following error in the console: "QSocketNotifier: Multiple socket notifiers for same socket 2068 and type Read"
As it is hosted on GitHub, you can find the desired version from the commit history and download that version easily.
First browse the commits:
https://github.com/spyder-ide/spyder/commits/master
After you find the version that doesn't break things. Then you can easily download and install it.
As mentioned before there is an option in the GUI now to select the preferred version.
But before that make sure to run conda update conda. At least in my case that helped.

stuck in using Megam in Python ( nltk.classify.MaxentClassifier)

I'm using ubuntu x64, after two days and searching all the net, still i've not been able to install Megam,
i've read all information in this page http://www.cs.utah.edu/~hal/megam/
and installed x64 version of o'calm from http://packages.ubuntu.com/precise/ocaml
but when i want to use "megam" as a classifier in python, it says:
"NLTK was unable to find the megam file! Use software specific
configuration paramaters or set the MEGAM environment variable.
could anybody tell me how can i install and make use of it in python?
i've downloaded "ocaml-3.12.1.tar.gz" but the "make" command doesn't work (as it's said in its readme).
i've downloaded "megam_i686.opt" too, but it's not executable and i cannot run it
any help?
thanks in advance
For the future users:
megam is now available on MAC through brew:
$brew tap homebrew/science
$brew install megam
Use config_megam() to tell NLTK where the Megam executable is located. See: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.classify.megam-module.html for details and documentation.
You also need to build MEGAM with the right 32/64 bit setting for your system. "megam_i686.opt" is for x86 iirc, so you should compile it for 64 bit. It is a while since I did this, but a simple build on an x64 system was all I needed: "Make doesn't work" is not very useful: I'm sure it gave you a few error messages...? Probably paths not set or are read only?
Edit: Looks like the above link is currently broken. The main Megam site can be found at:
http://www.umiacs.umd.edu/~hal/megam/
although it hasn't been updated for a while.
Answer given by Hugh Perkins, helped me resolve the issue (due to low reputation can't add a comment to that answer). After downloading the zip file (from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip), I needed to tell python where it was, and that was done by adding it in os.environ as:
os.environ["MEGAM"] = '<<Complete path followed by file name>>/megam-64'
I downloaded from http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip , which was linked from http://thinknook.com/nltk-megam-maximum-entropy-library-on-64-bit-linux-2012-11-27/ This worked ok for me, on ubuntu 14.04
I manged to get megam to run on my docker instance running debian 9.7 following the steps below. Based on steps for MacOS install steps suggested by Jack Hong here.
apt-get install make
apt-get install ocaml-nox (or apt-get install ocaml, if you want x window support)
download source from here
unzip source creating a megam_0.92 directory
Edit the Makefile in megam_0.92 and make the following changes. (The
first change was already done in my particular instance):
WITHCLIBS=-I /usr/local/lib/ocaml/caml
WITHSTR =str.cma -cclib -lcamlstr
Save the changes and run make inside your megam_0.92 directory
add nltk.config_megam('//megam_0.92/megam') to your script and all should be well.

How do I install GASP for Python 2.6.2 on a Mac

I'm currently trying to learn Python and am going through How to Think Like a Computer Scientist: Learning With Python. I have installed Python 2.6.2 on Mac OSX 10.4.11 and am using the IDLE.
At the end of chapter 4 Elkner et al. refer to GASP. However their instructions don't work as when I enter:
>>> from gasp import*
I get:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
from gasp import*
ImportError: No module named gasp
I've had a look around on google and can only find outdated methods of installation or pages of gobbledegook. I believe I have to install PyObjC first and haven't been able to accomplish this either.
Can anyone please help me out with some plain English instructions?
Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion.
Install macport binary (comes with installer; easy)
sudo port install py-game
not sure if this is necessary, as it doesn’t appear to cause pygame to be functional for python version 2.7.1 (stock python on lion)
sudo port select --set python python 2.7
I believe this set the default python version to 2.7.2 which I also believe was
downloaded during step 2 (therefore why I think this ends up being a necessary step)
Download setuptools-0.6c11-py2.7.tar
In folder gasp-0.3.4, which appears after clicking on the .tar, place setup.py in the
gasp folder
sudo python gasp/setup.py install
make sure your directory is the folder gasp-0.3.4
sudo port –v install py27-pygtk
takes about an hour for this step to complete
sudo port uninstall py-game
this step is not necessary for gasp to work; I simply didn’t want any unnecessary
stuff on my computer that was downloaded during the second step; however, this step
put python 2.7.2 on my computer; could install 2.7.2 separately I guess but this way
worked for me; a lot of other unnecessary stuff is installed during this step too but
I think it’ll remain even after this command, oh well
This is actually somewhat of a coincidence; I'm one of the packagers of GASP. On our download page, which is linked by our main project page, there are instructions on how to install it on most major platforms. Hadn't considered OSX, however. Will write something up shortly.
Essentially, install the Official Python from the PSF. Then add MacPorts and run
sudo ports install py-game
Extract the source tarball from the download page linked above to your site-packages directory.
There are also some alternative instructions I found that might work better, as I have not tested the above.
This is an interesting problem faced by most of the readers using "How to Think Like a Computer Scientist : Learning with Python", when they reach 4th chapter.
Now to install GASP, you need to check whether you have python installed on your machine.
Assumption: I am going to assume that you are using Mac.
Type the following command on your terminal,
`$ python -V`
{If your system has python installed on it, you will get an answer like Python 2.7.1 ( if the version is 2.7.1).}
Once you have python available on your system, you should install PyObjC.
An easy way out is to type on to your terminal prompt,
`$ easy_install pyobjc==2.2`
{this will install the version 2.2}
Next step is to install pygame package , you can do this in two ways either by downloading the .dmg file or using "homebrew". I prefer the second method.
to install pygame package using "brew" you have to install mercurial first. It's a simple procedure, just type in
$ brew install mercurial
Then type in the following commands,
$ brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi
$ sudo pip install hg+http://bitbucket.org/pygame/pygame
Next step is to install GASP. Download gasp from https://launchpad.net/gasp-core/+download
Extract the .tar file, you will get a folder structure. Our aim is to copy the folder named "gasp" to the Systems Library folder. To check which folder or version of python is used and to know their correct path type in the following command on terminal.
$ python -c 'import sys, pprint; pprint.pprint(sys.path)'
generally it will print a path similar to '/Library/Python/2.7/site-packages' , you can notice this either as the last line or the second last line of the output that above commands generate.
Copy the gasp folder to the site-packages folder,
$ sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Python/2.7/site-packages/gasp
This should copy all the required files to the location specified as the second argument.
Now go to terminal and type
$ python
>>> import gasp
If everything goes fine, you will not get any error or any messages.
PS: Ensure that in your site-packages directory there are no duplicate copies of pygame/gasp. In case of duplicates, it may throw lots of tantrums. Also, if any of the steps go wrong you may get error "import cairo" some 25th or 26th line on base.py in gasp package.In that event, please clean up your site packages directory by removing pygame and gasp and re-install them, that should solve it.
Also while installing mercurial you may get some warning related to Certificates. You can solve them by typing in following commands,
$ openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650
$ sudo cp dummycert.pem /etc/hg-dummy-cert.pem
$ cd ~
$ nano .hgrc
{ This will open up an empty .hgrc file }
Type in the following
[web]
cacerts = /etc/hg-dummy-cert.pem
save the above 2 lines by pressing ctrl+ o
exit nano by pressing ctrl + x
Thats it. This should solve your problems with GASP installation and enjoy the book " How to Think Like a Computer Scientist" it's a wonderful introduction to the world of computing.

Categories